flash-sdk 12.0.0 → 12.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/CustodyAccount.d.ts +1 -1
  2. package/dist/MarketAccount.d.ts +2 -2
  3. package/dist/OraclePrice.d.ts +0 -1
  4. package/dist/OrderAccount.d.ts +0 -1
  5. package/dist/PerpetualsClient.d.ts +325 -4360
  6. package/dist/PerpetualsClient.js +1205 -558
  7. package/dist/PoolAccount.d.ts +0 -1
  8. package/dist/PoolConfig.d.ts +3 -1
  9. package/dist/PoolConfig.js +30 -2
  10. package/dist/PoolConfig.json +955 -133
  11. package/dist/PoolDataClient.d.ts +0 -1
  12. package/dist/PositionAccount.d.ts +3 -3
  13. package/dist/TokenStakeAccount.d.ts +0 -1
  14. package/dist/TokenVaultAccount.d.ts +0 -1
  15. package/dist/ViewHelper.d.ts +2 -1
  16. package/dist/ViewHelper.js +11 -8
  17. package/dist/backupOracle.js +27 -6
  18. package/dist/constants/index.d.ts +0 -1
  19. package/dist/idl/perpetuals.d.ts +26433 -13458
  20. package/dist/idl/perpetuals.js +0 -18010
  21. package/dist/idl/perpetuals.json +30985 -0
  22. package/dist/index.d.ts +3 -1
  23. package/dist/index.js +6 -2
  24. package/dist/remoraTokensWithPriceIds.d.ts +13 -0
  25. package/dist/remoraTokensWithPriceIds.js +265 -0
  26. package/dist/testPublkey.d.ts +0 -0
  27. package/dist/testPublkey.js +0 -0
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/dist/types/generated.d.ts +2275 -0
  30. package/dist/types/generated.js +2 -0
  31. package/dist/types/index.d.ts +47 -160
  32. package/dist/types/index.js +22 -6
  33. package/dist/utils/IdlCoder.d.ts +3 -2
  34. package/dist/utils/IdlCoder.js +21 -9
  35. package/dist/utils/alt.js +5 -6
  36. package/dist/utils/anchorCpiEvents.d.ts +1 -2
  37. package/dist/utils/anchorCpiEvents.js +14 -10
  38. package/dist/utils/index.js +6 -6
  39. package/dist/utils/rpc.js +9 -9
  40. package/package.json +3 -3
  41. package/readme.md +37 -3
  42. package/dist/idl/fbnft_rewards.d.ts +0 -290
  43. package/dist/idl/fbnft_rewards.js +0 -292
  44. package/dist/idl/perp_composability.d.ts +0 -760
  45. package/dist/idl/perp_composability.js +0 -762
  46. package/dist/idl/reward_distribution.d.ts +0 -347
  47. package/dist/idl/reward_distribution.js +0 -349
@@ -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.");
@@ -68,10 +68,7 @@ var bs58_1 = require("bs58");
68
68
  var PositionAccount_1 = require("./PositionAccount");
69
69
  var types_1 = require("./types");
70
70
  var OraclePrice_1 = require("./OraclePrice");
71
- var perpetuals_1 = require("./idl/perpetuals");
72
- var perp_composability_1 = require("./idl/perp_composability");
73
- var fbnft_rewards_1 = require("./idl/fbnft_rewards");
74
- var reward_distribution_1 = require("./idl/reward_distribution");
71
+ var perpetuals_json_1 = __importDefault(require("./idl/perpetuals.json"));
75
72
  var rpc_1 = require("./utils/rpc");
76
73
  var utils_1 = require("./utils");
77
74
  var constants_1 = require("./constants");
@@ -86,44 +83,83 @@ var PerpetualsClient = (function () {
86
83
  if (useExtOracleAccount === void 0) { useExtOracleAccount = false; }
87
84
  var _this = this;
88
85
  var _a;
89
- this.addressLookupTables = [];
86
+ this.poolAddressLookupTables = new Map();
87
+ this.poolPusherAddressLookupTables = new Map();
90
88
  this.setPrioritizationFee = function (fee) {
91
89
  _this.prioritizationFee = fee;
92
90
  };
93
91
  this.loadAddressLookupTable = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
94
- var addresses, _i, _a, address, addressLookupTable, _b, accCreationLamports;
92
+ var addressLookupTables, _a, accCreationLamports;
93
+ return __generator(this, function (_b) {
94
+ switch (_b.label) {
95
+ case 0: return [4, this.getOrLoadAddressLookupTable(poolConfig)];
96
+ case 1:
97
+ addressLookupTables = (_b.sent()).addressLookupTables;
98
+ if (!(!this.pusherAddressLookupTables || this.pusherAddressLookupTables.isActive() === false)) return [3, 3];
99
+ _a = this;
100
+ return [4, this.provider.connection.getAddressLookupTable(poolConfig.pusherAddressLookupTableAddress)];
101
+ case 2:
102
+ _a.pusherAddressLookupTables = (_b.sent()).value;
103
+ _b.label = 3;
104
+ case 3:
105
+ if (!!this.minimumBalanceForRentExemptAccountLamports) return [3, 5];
106
+ return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
107
+ case 4:
108
+ accCreationLamports = (_b.sent());
109
+ if (accCreationLamports) {
110
+ this.minimumBalanceForRentExemptAccountLamports = accCreationLamports;
111
+ }
112
+ _b.label = 5;
113
+ case 5: return [2];
114
+ }
115
+ });
116
+ }); };
117
+ this.getOrLoadAddressLookupTable = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
118
+ var addresses, addressesToLoad, _i, _a, address, addressKey, cached, _b, addressesToLoad_1, address, addressLookupTable, accCreationLamports;
95
119
  return __generator(this, function (_c) {
96
120
  switch (_c.label) {
97
121
  case 0:
98
122
  addresses = [];
99
- _i = 0, _a = poolConfig.addressLookupTableAddresses;
123
+ addressesToLoad = [];
124
+ for (_i = 0, _a = poolConfig.addressLookupTableAddresses; _i < _a.length; _i++) {
125
+ address = _a[_i];
126
+ addressKey = address.toBase58();
127
+ cached = this.poolAddressLookupTables.get(addressKey);
128
+ if (cached) {
129
+ addresses.push(cached);
130
+ }
131
+ else {
132
+ addressesToLoad.push(address);
133
+ }
134
+ }
135
+ _b = 0, addressesToLoad_1 = addressesToLoad;
100
136
  _c.label = 1;
101
137
  case 1:
102
- if (!(_i < _a.length)) return [3, 4];
103
- address = _a[_i];
138
+ if (!(_b < addressesToLoad_1.length)) return [3, 4];
139
+ address = addressesToLoad_1[_b];
104
140
  return [4, this.provider.connection.getAddressLookupTable(address)];
105
141
  case 2:
106
142
  addressLookupTable = (_c.sent()).value;
107
143
  if (addressLookupTable) {
108
144
  addresses.push(addressLookupTable);
145
+ this.poolAddressLookupTables.set(address.toBase58(), addressLookupTable);
109
146
  }
110
147
  _c.label = 3;
111
148
  case 3:
112
- _i++;
149
+ _b++;
113
150
  return [3, 1];
114
151
  case 4:
115
- this.addressLookupTables = addresses;
116
- _b = this;
117
- return [4, this.provider.connection.getAddressLookupTable(poolConfig.pusherAddressLookupTableAddress)];
118
- case 5:
119
- _b.pusherAddressLookupTables = (_c.sent()).value;
152
+ if (!!this.minimumBalanceForRentExemptAccountLamports) return [3, 6];
120
153
  return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
121
- case 6:
154
+ case 5:
122
155
  accCreationLamports = (_c.sent());
123
156
  if (accCreationLamports) {
124
157
  this.minimumBalanceForRentExemptAccountLamports = accCreationLamports;
125
158
  }
126
- return [2];
159
+ _c.label = 6;
160
+ case 6: return [2, {
161
+ addressLookupTables: addresses,
162
+ }];
127
163
  }
128
164
  });
129
165
  }); };
@@ -226,11 +262,6 @@ var PerpetualsClient = (function () {
226
262
  tokenMint,
227
263
  ]).publicKey;
228
264
  };
229
- this.getTradingAccount = function (tradingAccount) { return __awaiter(_this, void 0, void 0, function () {
230
- return __generator(this, function (_a) {
231
- return [2, this.program.account.trading.fetch(tradingAccount)];
232
- });
233
- }); };
234
265
  this.getPosition = function (postionKey) { return __awaiter(_this, void 0, void 0, function () {
235
266
  return __generator(this, function (_a) {
236
267
  return [2, this.program.account.position.fetch(postionKey)];
@@ -249,7 +280,7 @@ var PerpetualsClient = (function () {
249
280
  _a.trys.push([1, 3, , 4]);
250
281
  return [4, this.program.methods
251
282
  .getPositionData({})
252
- .accounts({
283
+ .accountsPartial({
253
284
  perpetuals: this.perpetuals.publicKey,
254
285
  pool: poolConfig.poolAddress,
255
286
  position: position.publicKey,
@@ -344,7 +375,7 @@ var PerpetualsClient = (function () {
344
375
  case 0: return [4, this.program.account.position.all()];
345
376
  case 1:
346
377
  allPositions = _a.sent();
347
- activePositions = allPositions.filter(function (f) { return !f.account.sizeAmount.isZero(); });
378
+ activePositions = allPositions.filter(function (f) { var _a; return !((_a = f.account.sizeAmount) === null || _a === void 0 ? void 0 : _a.isZero()); });
348
379
  return [2, activePositions];
349
380
  }
350
381
  });
@@ -354,7 +385,7 @@ var PerpetualsClient = (function () {
354
385
  return __generator(this, function (_a) {
355
386
  switch (_a.label) {
356
387
  case 0:
357
- data = (0, bs58_1.encode)(Buffer.concat([marketKey.toBuffer()]));
388
+ data = (0, bs58_1.encode)(new Uint8Array(marketKey.toBuffer()));
358
389
  return [4, this.program.account.position.all([
359
390
  {
360
391
  memcmp: { bytes: data, offset: 40 }
@@ -371,7 +402,7 @@ var PerpetualsClient = (function () {
371
402
  return __generator(this, function (_a) {
372
403
  switch (_a.label) {
373
404
  case 0:
374
- data = (0, bs58_1.encode)(Buffer.concat([marketKey.toBuffer()]));
405
+ data = (0, bs58_1.encode)(new Uint8Array(marketKey.toBuffer()));
375
406
  return [4, this.program.account.position.all([
376
407
  {
377
408
  memcmp: { bytes: data, offset: 40 }
@@ -379,7 +410,7 @@ var PerpetualsClient = (function () {
379
410
  ])];
380
411
  case 1:
381
412
  allPositions = _a.sent();
382
- activePositions = allPositions.filter(function (f) { return !f.account.sizeAmount.isZero(); });
413
+ activePositions = allPositions.filter(function (f) { var _a; return !((_a = f.account.sizeAmount) === null || _a === void 0 ? void 0 : _a.isZero()); });
383
414
  return [2, activePositions];
384
415
  }
385
416
  });
@@ -414,7 +445,7 @@ var PerpetualsClient = (function () {
414
445
  collateralCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(collateralMint); });
415
446
  return [4, this.program.methods
416
447
  .liquidate({})
417
- .accounts({
448
+ .accountsPartial({
418
449
  signer: this.provider.wallet.publicKey,
419
450
  perpetuals: this.perpetuals.publicKey,
420
451
  pool: poolConfig.poolAddress,
@@ -424,7 +455,6 @@ var PerpetualsClient = (function () {
424
455
  targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
425
456
  collateralCustody: collateralCustodyConfig.custodyAccount,
426
457
  collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
427
- eventAuthority: this.eventAuthority.publicKey,
428
458
  program: this.program.programId,
429
459
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
430
460
  })
@@ -707,7 +737,7 @@ var PerpetualsClient = (function () {
707
737
  var sizeAmount = positionAccount.sizeAmount.add(sizeDeltaAmount);
708
738
  var sizeAmountUsd = entryOraclePrice.getAssetAmountUsd(sizeAmount, targetTokenCustodyAccount.decimals);
709
739
  if (enableDebuglogs) {
710
- console.log("SDK logs : finalCollateralUsd:", finalCollateralUsd.toString(), "finalCollateralAmount:", finalCollateralAmount.toString(), "sizeAmount:", sizeAmount.toString(), "sizeAmountUsd:", sizeAmountUsd.toString(), "sizeDeltaAmount:", sizeDeltaAmount.toString(), "sizeUsd:", sizeUsd.toString(), "currentCollateralUsdIncludingPnl:", currentCollateralUsdIncludingPnl.toString(), "finalCollateralUsd :", finalCollateralUsd.toString(), "pnlUsd :", pnlUsd.toString());
740
+ console.log("SDK logs : finalCollateralUsd:", finalCollateralUsd.toString(), "finalCollateralAmount:", finalCollateralAmount.toString(), "size_amount:", sizeAmount.toString(), "sizeAmountUsd:", sizeAmountUsd.toString(), "sizeDeltaAmount:", sizeDeltaAmount.toString(), "sizeUsd:", sizeUsd.toString(), "currentCollateralUsdIncludingPnl:", currentCollateralUsdIncludingPnl.toString(), "finalCollateralUsd :", finalCollateralUsd.toString(), "pnlUsd :", pnlUsd.toString());
711
741
  }
712
742
  if (currentCollateralUsdIncludingPnl.gt(constants_1.BN_ZERO)) {
713
743
  return sizeAmountUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(currentCollateralUsdIncludingPnl);
@@ -827,7 +857,7 @@ var PerpetualsClient = (function () {
827
857
  if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
828
858
  throw new Error("Delta Amounts cannot be negative ");
829
859
  }
830
- if (resultingPositionAccount.collateralAmount.isNeg() || resultingPositionAccount.sizeAmount.isNeg()) {
860
+ if (resultingPositionAccount.collateralUsd.isNeg() || resultingPositionAccount.sizeAmount.isNeg()) {
831
861
  throw new Error("cannot remove/close more than collateral/Size");
832
862
  }
833
863
  var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
@@ -998,6 +1028,7 @@ var PerpetualsClient = (function () {
998
1028
  positionDelta.collateralUsd = (positionAccount.collateralUsd.mul(closeRatio)).div(decimalPower);
999
1029
  positionDelta.unsettledFeesUsd = (positionAccount.unsettledFeesUsd.mul(closeRatio)).div(decimalPower);
1000
1030
  positionDelta.degenSizeUsd = positionAccount.degenSizeUsd.mul(closeRatio).div(decimalPower);
1031
+ positionDelta.priceImpactUsd = (positionAccount.priceImpactUsd.mul(closeRatio)).div(decimalPower);
1001
1032
  var newPnl = _this.getPnlSync(positionDelta, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
1002
1033
  var exitFeeUsd = positionDelta.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
1003
1034
  if (discountBps.gt(constants_1.BN_ZERO)) {
@@ -1007,7 +1038,8 @@ var PerpetualsClient = (function () {
1007
1038
  var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionDelta, collateralCustodyAccount, currentTimestamp);
1008
1039
  var totalFeesUsd = (exitFeeUsd.add(lockAndUnsettledFeeUsd));
1009
1040
  var currentCollateralUsd = positionDelta.collateralUsd;
1010
- var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
1041
+ var lossLiabilityUsd = newPnl.lossUsd.add(positionDelta.priceImpactUsd);
1042
+ var liabilityUsd = lossLiabilityUsd.add(totalFeesUsd);
1011
1043
  var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(currentCollateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionDelta.lockedAmount, collateralCustodyAccount.decimals));
1012
1044
  if (debugLogs) {
1013
1045
  console.log("assetsUsd.sub(liabilityUsd):", collateralCustodyAccount.decimals, assetsUsd.toString(), liabilityUsd.toString(), assetsUsd.sub(liabilityUsd).toString());
@@ -1036,6 +1068,7 @@ var PerpetualsClient = (function () {
1036
1068
  newPosition.collateralUsd = positionAccount.collateralUsd.sub(positionDelta.collateralUsd);
1037
1069
  newPosition.unsettledFeesUsd = positionAccount.unsettledFeesUsd.sub(positionDelta.unsettledFeesUsd);
1038
1070
  newPosition.degenSizeUsd = positionAccount.degenSizeUsd.sub(positionDelta.degenSizeUsd);
1071
+ newPosition.priceImpactUsd = positionAccount.priceImpactUsd.sub(positionDelta.priceImpactUsd);
1039
1072
  newPosition.collateralUsd = newPosition.collateralUsd.add(closeAmountUsd);
1040
1073
  var feeUsdWithDiscount = constants_1.BN_ZERO;
1041
1074
  var feeUsd = sizeDeltaUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
@@ -1103,7 +1136,8 @@ var PerpetualsClient = (function () {
1103
1136
  var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
1104
1137
  var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
1105
1138
  var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
1106
- var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
1139
+ var lossLiabilityUsd = profitLoss.lossUsd.add(positionAccount.priceImpactUsd);
1140
+ var lossUsd = lossLiabilityUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
1107
1141
  var availableInitMarginUsd = constants_1.BN_ZERO;
1108
1142
  if (profitLoss.lossUsd.lt(positionAccount.collateralUsd)) {
1109
1143
  availableInitMarginUsd = positionAccount.collateralUsd.sub(lossUsd);
@@ -1142,9 +1176,11 @@ var PerpetualsClient = (function () {
1142
1176
  var position = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
1143
1177
  var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
1144
1178
  var newPnl = _this.getPnlSync(position, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
1145
- var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, positionAccount.collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
1179
+ var collateralAmount = collateralPrice.getTokenAmount(positionAccount.collateralUsd, collateralCustodyAccount.decimals);
1180
+ var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
1146
1181
  var totalFeesUsd = (exitPriceAndFee.exitFeeUsd.add(exitPriceAndFee.borrowFeeUsd));
1147
- var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
1182
+ var lossLiabilityUsd = newPnl.lossUsd.add(positionAccount.priceImpactUsd);
1183
+ var liabilityUsd = lossLiabilityUsd.add(totalFeesUsd);
1148
1184
  var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(positionAccount.collateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionAccount.lockedAmount, collateralCustodyAccount.decimals));
1149
1185
  var closeAmountUsd, feesAmountUsd;
1150
1186
  if (assetsUsd.gt(liabilityUsd)) {
@@ -1199,7 +1235,8 @@ var PerpetualsClient = (function () {
1199
1235
  var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
1200
1236
  var exitFeeUsd = positionAccount.sizeUsd.mul(targetCustodyAccount.fees.closePosition).div(new anchor_1.BN(constants_1.RATE_POWER));
1201
1237
  var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
1202
- var lossUsd = profitLoss.lossUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
1238
+ var lossLiabilityUsd = profitLoss.lossUsd.add(positionAccount.priceImpactUsd);
1239
+ var lossUsd = lossLiabilityUsd.add(exitFeeUsd).add(lockAndUnsettledFeeUsd);
1203
1240
  var currentCollateralUsd = positionAccount.collateralUsd;
1204
1241
  var availableInitMarginUsd = constants_1.BN_ZERO;
1205
1242
  if (profitLoss.lossUsd.lt(currentCollateralUsd)) {
@@ -1411,7 +1448,7 @@ var PerpetualsClient = (function () {
1411
1448
  }
1412
1449
  return liquidationPrice.price.isNeg() ? zeroOraclePrice : liquidationPrice;
1413
1450
  };
1414
- this.getMaxProfitPriceSync = function (entryPrice, marketCorrelation, side, collateralPrice, positionAccount) {
1451
+ this.getMaxProfitPriceSync = function (entryPrice, marketCorrelation, side, collateralPrice, collateralDecimals, positionAccount) {
1415
1452
  var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
1416
1453
  price: constants_1.BN_ZERO,
1417
1454
  exponent: constants_1.BN_ZERO,
@@ -1422,7 +1459,7 @@ var PerpetualsClient = (function () {
1422
1459
  return zeroOraclePrice;
1423
1460
  }
1424
1461
  var priceDiffProfit = OraclePrice_1.OraclePrice.from({
1425
- price: (collateralPrice.price.mul(positionAccount.lockedAmount)).mul(new anchor_1.BN(10).pow(new anchor_1.BN(positionAccount.sizeDecimals + 3)))
1462
+ price: (collateralPrice.getAssetAmountUsd(positionAccount.lockedAmount, collateralDecimals)).mul(new anchor_1.BN(10).pow(new anchor_1.BN(positionAccount.sizeDecimals + 3)))
1426
1463
  .div(positionAccount.sizeAmount),
1427
1464
  exponent: new anchor_1.BN(-1 * constants_1.RATE_DECIMALS),
1428
1465
  confidence: constants_1.BN_ZERO,
@@ -1561,6 +1598,7 @@ var PerpetualsClient = (function () {
1561
1598
  return {
1562
1599
  profitUsd: constants_1.BN_ZERO,
1563
1600
  lossUsd: constants_1.BN_ZERO,
1601
+ priceImpactUsd: constants_1.BN_ZERO,
1564
1602
  };
1565
1603
  }
1566
1604
  var side = poolConfig.getMarketConfigByPk(positionAccount.market).side;
@@ -1583,8 +1621,14 @@ var PerpetualsClient = (function () {
1583
1621
  priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1584
1622
  }
1585
1623
  else {
1586
- priceDiffProfit = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1587
- priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1624
+ if (positionAccount.referencePrice.price.gt(positionEntryPrice.price)) {
1625
+ priceDiffProfit = new OraclePrice_1.OraclePrice({ price: positionAccount.referencePrice.price.sub(positionEntryPrice.price), exponent: positionEntryPrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1626
+ priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1627
+ }
1628
+ else {
1629
+ priceDiffProfit = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1630
+ priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1631
+ }
1588
1632
  }
1589
1633
  }
1590
1634
  else {
@@ -1599,8 +1643,14 @@ var PerpetualsClient = (function () {
1599
1643
  priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1600
1644
  }
1601
1645
  else {
1602
- priceDiffProfit = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1603
- priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1646
+ if (positionEntryPrice.price.gt(positionAccount.referencePrice.price)) {
1647
+ priceDiffProfit = new OraclePrice_1.OraclePrice({ price: positionEntryPrice.price.sub(positionAccount.referencePrice.price), exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1648
+ priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1649
+ }
1650
+ else {
1651
+ priceDiffProfit = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1652
+ priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1653
+ }
1604
1654
  }
1605
1655
  }
1606
1656
  else {
@@ -1613,19 +1663,96 @@ var PerpetualsClient = (function () {
1613
1663
  throw new Error("exponent mistach");
1614
1664
  }
1615
1665
  if (priceDiffProfit.price.gt(constants_1.BN_ZERO)) {
1666
+ var grossProfitUsd = priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals);
1616
1667
  return {
1617
- profitUsd: priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
1668
+ profitUsd: grossProfitUsd,
1618
1669
  lossUsd: constants_1.BN_ZERO,
1670
+ priceImpactUsd: positionAccount.priceImpactUsd,
1619
1671
  };
1620
1672
  }
1621
1673
  else {
1674
+ var grossLossUsd = priceDiffLoss.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals);
1622
1675
  return {
1623
1676
  profitUsd: constants_1.BN_ZERO,
1624
- lossUsd: priceDiffLoss.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
1677
+ lossUsd: grossLossUsd,
1678
+ priceImpactUsd: positionAccount.priceImpactUsd,
1679
+ };
1680
+ }
1681
+ };
1682
+ this.getPositionMetrics = function (positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig) {
1683
+ if (positionAccount.sizeUsd.isZero() || positionAccount.entryPrice.price.isZero()) {
1684
+ var zeroOraclePrice = OraclePrice_1.OraclePrice.from({
1685
+ price: constants_1.BN_ZERO,
1686
+ exponent: constants_1.BN_ZERO,
1687
+ confidence: constants_1.BN_ZERO,
1688
+ timestamp: constants_1.BN_ZERO
1689
+ });
1690
+ return {
1691
+ pnl: { profitUsd: constants_1.BN_ZERO, lossUsd: constants_1.BN_ZERO, priceImpactUsd: constants_1.BN_ZERO },
1692
+ leverage: constants_1.BN_ZERO,
1693
+ liquidationPrice: zeroOraclePrice,
1694
+ fees: { exitFeeUsd: constants_1.BN_ZERO, exitFeeAmount: constants_1.BN_ZERO, lockAndUnsettledFeeUsd: constants_1.BN_ZERO }
1625
1695
  };
1626
1696
  }
1697
+ var side = poolConfig.getMarketConfigByPk(positionAccount.market).side;
1698
+ var entryOraclePrice = OraclePrice_1.OraclePrice.from({
1699
+ price: positionAccount.entryPrice.price,
1700
+ exponent: new anchor_1.BN(positionAccount.entryPrice.exponent),
1701
+ confidence: constants_1.BN_ZERO,
1702
+ timestamp: constants_1.BN_ZERO
1703
+ });
1704
+ var exitOraclePrice = _this.getExitOraclePriceSync(side, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, positionAccount.sizeUsd);
1705
+ var lockAndUnsettledFeeUsd = _this.getLockFeeAndUnsettledUsdForPosition(positionAccount, collateralCustodyAccount, currentTimestamp);
1706
+ var _a = _this.getExitFeeSync(positionAccount, targetCustodyAccount, collateralCustodyAccount, collateralPrice, collateralEmaPrice), exitFeeAmount = _a.exitFeeAmount, exitFeeUsd = _a.exitFeeUsd;
1707
+ var pnl;
1708
+ if (!exitOraclePrice.exponent.eq(entryOraclePrice.exponent)) {
1709
+ throw new Error("exponent mismatch");
1710
+ }
1711
+ var pnlResult = _this.getPnlContractHelper(positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
1712
+ pnl = {
1713
+ profitUsd: pnlResult.profitUsd,
1714
+ lossUsd: pnlResult.lossUsd,
1715
+ priceImpactUsd: pnlResult.priceImpactUsd,
1716
+ };
1717
+ var liquidationPrice = _this.getLiquidationPriceContractHelper(entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount);
1718
+ var unsettledFeesUsd = exitFeeUsd.add(lockAndUnsettledFeeUsd);
1719
+ var lossUsd = pnl.lossUsd.add(unsettledFeesUsd);
1720
+ var currentMarginUsd = positionAccount.collateralUsd.add(pnl.profitUsd).sub(lossUsd);
1721
+ var leverage;
1722
+ if (currentMarginUsd.gt(constants_1.BN_ZERO)) {
1723
+ leverage = positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(currentMarginUsd);
1724
+ }
1725
+ else {
1726
+ leverage = new anchor_1.BN(Number.MAX_SAFE_INTEGER);
1727
+ }
1728
+ return {
1729
+ pnl: pnl,
1730
+ leverage: leverage,
1731
+ liquidationPrice: liquidationPrice,
1732
+ fees: {
1733
+ exitFeeUsd: exitFeeUsd,
1734
+ exitFeeAmount: exitFeeAmount,
1735
+ lockAndUnsettledFeeUsd: lockAndUnsettledFeeUsd
1736
+ }
1737
+ };
1738
+ };
1739
+ this.getPositionsMetricsBatch = function (positions, priceMap, currentTimestamp) {
1740
+ var results = new Map();
1741
+ for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) {
1742
+ var _a = positions_1[_i], positionAccount = _a.positionAccount, targetCustodyAccount = _a.targetCustodyAccount, collateralCustodyAccount = _a.collateralCustodyAccount, poolConfig = _a.poolConfig;
1743
+ var positionKey = positionAccount.publicKey.toBase58();
1744
+ var targetPrices = priceMap.get(targetCustodyAccount.publicKey.toBase58());
1745
+ var collateralPrices = priceMap.get(collateralCustodyAccount.publicKey.toBase58());
1746
+ if (!targetPrices || !collateralPrices) {
1747
+ continue;
1748
+ }
1749
+ var metrics = _this.getPositionMetrics(positionAccount, targetPrices.price, targetPrices.emaPrice, targetCustodyAccount, collateralPrices.price, collateralPrices.emaPrice, collateralCustodyAccount, currentTimestamp, poolConfig);
1750
+ results.set(positionKey, metrics);
1751
+ }
1752
+ return results;
1627
1753
  };
1628
- this.getSwapAmountAndFeesSync = function (amountIn, amountOut, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, outputTokenPrice, outputTokenEmaPrice, outputTokenCustodyAccount, poolAumUsdMax, poolConfig) {
1754
+ this.getSwapAmountAndFeesSync = function (amountIn, amountOut, poolAccount, inputTokenPrice, inputTokenEmaPrice, inputTokenCustodyAccount, outputTokenPrice, outputTokenEmaPrice, outputTokenCustodyAccount, poolAumUsdMax, poolConfig, whitelistedUserAccount) {
1755
+ if (whitelistedUserAccount === void 0) { whitelistedUserAccount = null; }
1629
1756
  if (!amountIn.isZero() && !amountOut.isZero()) {
1630
1757
  throw new Error("both amountIn and amountOut cannot be non-zero");
1631
1758
  }
@@ -1637,6 +1764,12 @@ var PerpetualsClient = (function () {
1637
1764
  feeOut: constants_1.BN_ZERO,
1638
1765
  };
1639
1766
  }
1767
+ var isWhitelistedUser = false;
1768
+ if (whitelistedUserAccount && whitelistedUserAccount.isSwapFeeExempt) {
1769
+ if (whitelistedUserAccount.pool.equals(poolAccount.publicKey) || whitelistedUserAccount.pool.equals(web3_js_1.PublicKey.default)) {
1770
+ isWhitelistedUser = true;
1771
+ }
1772
+ }
1640
1773
  var newInputTokenPrice, newInputTokenEmaPrice;
1641
1774
  var newOutputTokenPrice, newOutputTokenEmaPrice;
1642
1775
  if (inputTokenPrice.exponent.lte(outputTokenPrice.exponent)) {
@@ -1672,8 +1805,10 @@ var PerpetualsClient = (function () {
1672
1805
  }
1673
1806
  var swapPrice = pairPrice.sub(pairPrice.mul(outputTokenCustodyAccount.pricing.swapSpread).div(new anchor_1.BN(constants_1.BPS_POWER)));
1674
1807
  inputTokenAmount = (0, utils_1.checkedDecimalMul)(amountOut, new anchor_1.BN(-1 * outputTokenCustodyAccount.decimals), swapPrice, inputMinMaxPrice.min.exponent, new anchor_1.BN(-1 * inputTokenCustodyAccount.decimals));
1675
- feeIn = _this.getFeeHelper(types_1.FeesAction.SwapIn, inputTokenAmount, constants_1.BN_ZERO, inputTokenCustodyAccount, inputMinMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
1676
- feeOut = _this.getFeeHelper(types_1.FeesAction.SwapOut, constants_1.BN_ZERO, amountOut, outputTokenCustodyAccount, outputMinMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
1808
+ feeIn = isWhitelistedUser ? constants_1.BN_ZERO
1809
+ : _this.getFeeHelper(types_1.FeesAction.SwapIn, inputTokenAmount, constants_1.BN_ZERO, inputTokenCustodyAccount, inputMinMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
1810
+ feeOut = isWhitelistedUser ? constants_1.BN_ZERO
1811
+ : _this.getFeeHelper(types_1.FeesAction.SwapOut, constants_1.BN_ZERO, amountOut, outputTokenCustodyAccount, outputMinMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
1677
1812
  var swapAmount = (0, utils_1.checkedDecimalMul)(amountOut.add(feeOut), new anchor_1.BN(-1 * outputTokenCustodyAccount.decimals), swapPrice, inputMinMaxPrice.min.exponent, new anchor_1.BN(-1 * inputTokenCustodyAccount.decimals)).add(feeIn);
1678
1813
  return {
1679
1814
  minAmountIn: swapAmount,
@@ -1693,8 +1828,10 @@ var PerpetualsClient = (function () {
1693
1828
  }
1694
1829
  var swapPrice = pairPrice.sub(pairPrice.mul(inputTokenCustodyAccount.pricing.swapSpread).div(new anchor_1.BN(constants_1.BPS_POWER)));
1695
1830
  outputTokenAmount = (0, utils_1.checkedDecimalMul)(amountIn, new anchor_1.BN(-1 * inputTokenCustodyAccount.decimals), swapPrice, inputMinMaxPrice.min.exponent, new anchor_1.BN(-1 * outputTokenCustodyAccount.decimals));
1696
- feeIn = _this.getFeeHelper(types_1.FeesAction.SwapIn, amountIn, constants_1.BN_ZERO, inputTokenCustodyAccount, inputMinMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
1697
- feeOut = _this.getFeeHelper(types_1.FeesAction.SwapOut, constants_1.BN_ZERO, outputTokenAmount, outputTokenCustodyAccount, outputMinMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
1831
+ feeIn = isWhitelistedUser ? constants_1.BN_ZERO
1832
+ : _this.getFeeHelper(types_1.FeesAction.SwapIn, amountIn, constants_1.BN_ZERO, inputTokenCustodyAccount, inputMinMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
1833
+ feeOut = isWhitelistedUser ? constants_1.BN_ZERO
1834
+ : _this.getFeeHelper(types_1.FeesAction.SwapOut, constants_1.BN_ZERO, outputTokenAmount, outputTokenCustodyAccount, outputMinMaxPrice.max, poolAumUsdMax, poolAccount, poolConfig).feeAmount;
1698
1835
  var swapAmount = (0, utils_1.checkedDecimalMul)(amountIn.sub(feeIn), new anchor_1.BN(-1 * inputTokenCustodyAccount.decimals), swapPrice, inputMinMaxPrice.min.exponent, new anchor_1.BN(-1 * outputTokenCustodyAccount.decimals)).sub(feeOut);
1699
1836
  return {
1700
1837
  minAmountIn: constants_1.BN_ZERO,
@@ -1826,69 +1963,204 @@ var PerpetualsClient = (function () {
1826
1963
  });
1827
1964
  });
1828
1965
  };
1829
- this.getStakedLpTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
1830
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, setCULimitIx, result, index, res;
1831
- var _d;
1832
- return __generator(this, function (_e) {
1833
- switch (_e.label) {
1834
- case 0:
1835
- backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
1836
- custodies = POOL_CONFIG.custodies;
1837
- custodyMetas = [];
1838
- marketMetas = [];
1839
- for (_i = 0, custodies_1 = custodies; _i < custodies_1.length; _i++) {
1840
- token = custodies_1[_i];
1841
- custodyMetas.push({
1842
- isSigner: false,
1843
- isWritable: false,
1844
- pubkey: token.custodyAccount,
1845
- });
1846
- }
1847
- for (_a = 0, custodies_2 = custodies; _a < custodies_2.length; _a++) {
1848
- custody = custodies_2[_a];
1849
- custodyMetas.push({
1850
- isSigner: false,
1851
- isWritable: false,
1852
- pubkey: custody.intOracleAccount,
1853
- });
1854
- }
1855
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
1856
- market = _c[_b];
1857
- marketMetas.push({
1858
- pubkey: market.marketAccount,
1859
- isSigner: false,
1860
- isWritable: false,
1861
- });
1862
- }
1863
- return [4, this.program.methods
1864
- .getLpTokenPrice({})
1865
- .accounts({
1866
- perpetuals: POOL_CONFIG.perpetuals,
1867
- pool: poolKey,
1868
- lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
1869
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
1870
- })
1871
- .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
1872
- .transaction()];
1873
- case 1:
1874
- transaction = _e.sent();
1875
- return [4, backUpOracleInstructionPromise];
1876
- case 2:
1877
- backUpOracleInstruction = _e.sent();
1878
- setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
1879
- transaction.instructions.unshift(setCULimitIx);
1880
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
1881
- return [4, this.viewHelper.simulateTransaction(transaction)];
1882
- case 3:
1883
- result = _e.sent();
1884
- index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getLpTokenPrice'; });
1885
- res = this.viewHelper.decodeLogs(result, index, 'getLpTokenPrice');
1886
- return [2, res.toString()];
1887
- }
1966
+ this.getLpTokenPriceView = function (poolConfig_1) {
1967
+ var args_1 = [];
1968
+ for (var _i = 1; _i < arguments.length; _i++) {
1969
+ args_1[_i - 1] = arguments[_i];
1970
+ }
1971
+ return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, includeRemainingAccounts) {
1972
+ var custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market;
1973
+ if (includeRemainingAccounts === void 0) { includeRemainingAccounts = true; }
1974
+ return __generator(this, function (_e) {
1975
+ switch (_e.label) {
1976
+ case 0:
1977
+ custodyAccountMetas = [];
1978
+ custodyOracleAccountMetas = [];
1979
+ markets = [];
1980
+ for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
1981
+ custody = _b[_a];
1982
+ custodyAccountMetas.push({
1983
+ pubkey: custody.custodyAccount,
1984
+ isSigner: false,
1985
+ isWritable: false,
1986
+ });
1987
+ custodyOracleAccountMetas.push({
1988
+ pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
1989
+ isSigner: false,
1990
+ isWritable: false,
1991
+ });
1992
+ }
1993
+ for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
1994
+ market = _d[_c];
1995
+ markets.push({
1996
+ pubkey: market.marketAccount,
1997
+ isSigner: false,
1998
+ isWritable: false,
1999
+ });
2000
+ }
2001
+ return [4, this.program.methods
2002
+ .getLpTokenPrice({})
2003
+ .accountsPartial({
2004
+ perpetuals: this.perpetuals.publicKey,
2005
+ pool: poolConfig.poolAddress,
2006
+ lpTokenMint: poolConfig.stakedLpTokenMint,
2007
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
2008
+ })
2009
+ .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
2010
+ .view()
2011
+ .catch(function (err) {
2012
+ console.error(err);
2013
+ throw err;
2014
+ })];
2015
+ case 1: return [2, _e.sent()];
2016
+ }
2017
+ });
1888
2018
  });
1889
- }); };
2019
+ };
2020
+ this.getStakedLpTokenPrice = function (poolKey_1, POOL_CONFIG_1) {
2021
+ var args_1 = [];
2022
+ for (var _i = 2; _i < arguments.length; _i++) {
2023
+ args_1[_i - 2] = arguments[_i];
2024
+ }
2025
+ return __awaiter(_this, __spreadArray([poolKey_1, POOL_CONFIG_1], args_1, true), void 0, function (poolKey, POOL_CONFIG, includeRemainingAccounts) {
2026
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_1, token, _b, custodies_2, custody, _c, _d, market, transaction, backUpOracleInstruction, setCULimitIx, addressLookupTables, result, index, res;
2027
+ var _e;
2028
+ if (includeRemainingAccounts === void 0) { includeRemainingAccounts = true; }
2029
+ return __generator(this, function (_f) {
2030
+ switch (_f.label) {
2031
+ case 0:
2032
+ backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2033
+ custodies = POOL_CONFIG.custodies;
2034
+ custodyMetas = [];
2035
+ marketMetas = [];
2036
+ for (_a = 0, custodies_1 = custodies; _a < custodies_1.length; _a++) {
2037
+ token = custodies_1[_a];
2038
+ custodyMetas.push({
2039
+ isSigner: false,
2040
+ isWritable: false,
2041
+ pubkey: token.custodyAccount,
2042
+ });
2043
+ }
2044
+ for (_b = 0, custodies_2 = custodies; _b < custodies_2.length; _b++) {
2045
+ custody = custodies_2[_b];
2046
+ custodyMetas.push({
2047
+ isSigner: false,
2048
+ isWritable: false,
2049
+ pubkey: custody.intOracleAccount,
2050
+ });
2051
+ }
2052
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2053
+ market = _d[_c];
2054
+ marketMetas.push({
2055
+ pubkey: market.marketAccount,
2056
+ isSigner: false,
2057
+ isWritable: false,
2058
+ });
2059
+ }
2060
+ return [4, this.program.methods
2061
+ .getLpTokenPrice({})
2062
+ .accountsPartial({
2063
+ perpetuals: POOL_CONFIG.perpetuals,
2064
+ pool: poolKey,
2065
+ lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
2066
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2067
+ })
2068
+ .remainingAccounts(includeRemainingAccounts ? __spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true) : [])
2069
+ .transaction()];
2070
+ case 1:
2071
+ transaction = _f.sent();
2072
+ return [4, backUpOracleInstructionPromise];
2073
+ case 2:
2074
+ backUpOracleInstruction = _f.sent();
2075
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2076
+ transaction.instructions.unshift(setCULimitIx);
2077
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2078
+ return [4, this.getOrLoadAddressLookupTable(POOL_CONFIG)];
2079
+ case 3:
2080
+ addressLookupTables = (_f.sent()).addressLookupTables;
2081
+ return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables)];
2082
+ case 4:
2083
+ result = _f.sent();
2084
+ index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'get_lp_token_price'; });
2085
+ res = this.viewHelper.decodeLogs(result, index, 'get_lp_token_price');
2086
+ return [2, res.toString()];
2087
+ }
2088
+ });
2089
+ });
2090
+ };
2091
+ this.getCompoundingLPTokenPrice = function (poolKey_1, POOL_CONFIG_1) {
2092
+ var args_1 = [];
2093
+ for (var _i = 2; _i < arguments.length; _i++) {
2094
+ args_1[_i - 2] = arguments[_i];
2095
+ }
2096
+ return __awaiter(_this, __spreadArray([poolKey_1, POOL_CONFIG_1], args_1, true), void 0, function (poolKey, POOL_CONFIG, includeRemainingAccounts) {
2097
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_3, token, _b, custodies_4, custody, _c, _d, market, backUpOracleInstruction, transaction, setCULimitIx, addressLookupTables, result, index, res;
2098
+ var _e;
2099
+ if (includeRemainingAccounts === void 0) { includeRemainingAccounts = true; }
2100
+ return __generator(this, function (_f) {
2101
+ switch (_f.label) {
2102
+ case 0:
2103
+ backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2104
+ custodies = POOL_CONFIG.custodies;
2105
+ custodyMetas = [];
2106
+ marketMetas = [];
2107
+ for (_a = 0, custodies_3 = custodies; _a < custodies_3.length; _a++) {
2108
+ token = custodies_3[_a];
2109
+ custodyMetas.push({
2110
+ isSigner: false,
2111
+ isWritable: false,
2112
+ pubkey: token.custodyAccount,
2113
+ });
2114
+ }
2115
+ for (_b = 0, custodies_4 = custodies; _b < custodies_4.length; _b++) {
2116
+ custody = custodies_4[_b];
2117
+ custodyMetas.push({
2118
+ isSigner: false,
2119
+ isWritable: false,
2120
+ pubkey: custody.intOracleAccount,
2121
+ });
2122
+ }
2123
+ for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
2124
+ market = _d[_c];
2125
+ marketMetas.push({
2126
+ pubkey: market.marketAccount,
2127
+ isSigner: false,
2128
+ isWritable: false,
2129
+ });
2130
+ }
2131
+ return [4, backUpOracleInstructionPromise];
2132
+ case 1:
2133
+ backUpOracleInstruction = _f.sent();
2134
+ return [4, this.program.methods
2135
+ .getCompoundingTokenPrice({})
2136
+ .accounts({
2137
+ perpetuals: POOL_CONFIG.perpetuals,
2138
+ pool: poolKey,
2139
+ lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
2140
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2141
+ })
2142
+ .remainingAccounts(includeRemainingAccounts ? __spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true) : [])
2143
+ .transaction()];
2144
+ case 2:
2145
+ transaction = _f.sent();
2146
+ setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2147
+ transaction.instructions.unshift(setCULimitIx);
2148
+ (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2149
+ return [4, this.getOrLoadAddressLookupTable(POOL_CONFIG)];
2150
+ case 3:
2151
+ addressLookupTables = (_f.sent()).addressLookupTables;
2152
+ return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables)];
2153
+ case 4:
2154
+ result = _f.sent();
2155
+ index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'get_compounding_token_price'; });
2156
+ res = this.viewHelper.decodeLogs(result, index, 'get_compounding_token_price');
2157
+ return [2, res.toString()];
2158
+ }
2159
+ });
2160
+ });
2161
+ };
1890
2162
  this.getAssetsUnderManagement = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
1891
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_3, token, _a, custodies_4, custody, _b, _c, market;
2163
+ var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_5, token, _a, custodies_6, custody, _b, _c, market;
1892
2164
  return __generator(this, function (_d) {
1893
2165
  switch (_d.label) {
1894
2166
  case 0:
@@ -1896,16 +2168,16 @@ var PerpetualsClient = (function () {
1896
2168
  custodies = POOL_CONFIG.custodies;
1897
2169
  custodyMetas = [];
1898
2170
  marketMetas = [];
1899
- for (_i = 0, custodies_3 = custodies; _i < custodies_3.length; _i++) {
1900
- token = custodies_3[_i];
2171
+ for (_i = 0, custodies_5 = custodies; _i < custodies_5.length; _i++) {
2172
+ token = custodies_5[_i];
1901
2173
  custodyMetas.push({
1902
2174
  isSigner: false,
1903
2175
  isWritable: false,
1904
2176
  pubkey: token.custodyAccount,
1905
2177
  });
1906
2178
  }
1907
- for (_a = 0, custodies_4 = custodies; _a < custodies_4.length; _a++) {
1908
- custody = custodies_4[_a];
2179
+ for (_a = 0, custodies_6 = custodies; _a < custodies_6.length; _a++) {
2180
+ custody = custodies_6[_a];
1909
2181
  custodyMetas.push({
1910
2182
  isSigner: false,
1911
2183
  isWritable: false,
@@ -1922,7 +2194,7 @@ var PerpetualsClient = (function () {
1922
2194
  }
1923
2195
  return [4, this.program.methods
1924
2196
  .getAssetsUnderManagement({})
1925
- .accounts({
2197
+ .accountsPartial({
1926
2198
  perpetuals: POOL_CONFIG.perpetuals,
1927
2199
  pool: poolKey,
1928
2200
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -1942,27 +2214,28 @@ var PerpetualsClient = (function () {
1942
2214
  for (var _i = 4; _i < arguments.length; _i++) {
1943
2215
  args_1[_i - 4] = arguments[_i];
1944
2216
  }
1945
- 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, enableBackupOracle) {
1946
- var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
2217
+ 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, enableBackupOracle, whitelist) {
2218
+ var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, whitelistMeta, depositCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, addressLookupTables, result, index, res;
1947
2219
  var _e;
1948
2220
  if (userPublicKey === void 0) { userPublicKey = undefined; }
1949
2221
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
2222
+ if (whitelist === void 0) { whitelist = undefined; }
1950
2223
  return __generator(this, function (_f) {
1951
2224
  switch (_f.label) {
1952
2225
  case 0:
1953
2226
  custodies = POOL_CONFIG.custodies;
1954
2227
  custodyMetas = [];
1955
2228
  marketMetas = [];
1956
- for (_a = 0, custodies_5 = custodies; _a < custodies_5.length; _a++) {
1957
- token = custodies_5[_a];
2229
+ for (_a = 0, custodies_7 = custodies; _a < custodies_7.length; _a++) {
2230
+ token = custodies_7[_a];
1958
2231
  custodyMetas.push({
1959
2232
  isSigner: false,
1960
2233
  isWritable: false,
1961
2234
  pubkey: token.custodyAccount,
1962
2235
  });
1963
2236
  }
1964
- for (_b = 0, custodies_6 = custodies; _b < custodies_6.length; _b++) {
1965
- custody = custodies_6[_b];
2237
+ for (_b = 0, custodies_8 = custodies; _b < custodies_8.length; _b++) {
2238
+ custody = custodies_8[_b];
1966
2239
  custodyMetas.push({
1967
2240
  isSigner: false,
1968
2241
  isWritable: false,
@@ -1977,12 +2250,17 @@ var PerpetualsClient = (function () {
1977
2250
  isWritable: false,
1978
2251
  });
1979
2252
  }
2253
+ whitelistMeta = {
2254
+ pubkey: whitelist,
2255
+ isSigner: false,
2256
+ isWritable: false,
2257
+ };
1980
2258
  depositCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(depositCustodyKey); });
1981
2259
  return [4, this.program.methods
1982
2260
  .getAddLiquidityAmountAndFee({
1983
2261
  amountIn: amount,
1984
2262
  })
1985
- .accounts({
2263
+ .accountsPartial({
1986
2264
  perpetuals: POOL_CONFIG.perpetuals,
1987
2265
  pool: poolKey,
1988
2266
  custody: depositCustodyKey,
@@ -1990,7 +2268,7 @@ var PerpetualsClient = (function () {
1990
2268
  lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
1991
2269
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
1992
2270
  })
1993
- .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2271
+ .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true), (whitelist ? [whitelistMeta] : []), true))
1994
2272
  .transaction()];
1995
2273
  case 1:
1996
2274
  transaction = _f.sent();
@@ -2002,8 +2280,11 @@ var PerpetualsClient = (function () {
2002
2280
  backUpOracleInstruction = _f.sent();
2003
2281
  (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2004
2282
  _f.label = 3;
2005
- case 3: return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2283
+ case 3: return [4, this.getOrLoadAddressLookupTable(POOL_CONFIG)];
2006
2284
  case 4:
2285
+ addressLookupTables = (_f.sent()).addressLookupTables;
2286
+ return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables, userPublicKey)];
2287
+ case 5:
2007
2288
  result = _f.sent();
2008
2289
  if (result.value.err) {
2009
2290
  console.error('error Simulation failed:::', result);
@@ -2013,8 +2294,8 @@ var PerpetualsClient = (function () {
2013
2294
  error: 'Simulation failed: ' + JSON.stringify(result.value.err),
2014
2295
  }];
2015
2296
  }
2016
- index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
2017
- res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
2297
+ index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'get_add_liquidity_amount_and_fee'; });
2298
+ res = this.viewHelper.decodeLogs(result, index, 'get_add_liquidity_amount_and_fee');
2018
2299
  return [2, {
2019
2300
  amount: res.amount,
2020
2301
  fee: res.fee,
@@ -2028,27 +2309,28 @@ var PerpetualsClient = (function () {
2028
2309
  for (var _i = 4; _i < arguments.length; _i++) {
2029
2310
  args_1[_i - 4] = arguments[_i];
2030
2311
  }
2031
- 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, enableBackupOracle) {
2032
- var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
2312
+ 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, enableBackupOracle, whitelist) {
2313
+ var custodies, custodyMetas, marketMetas, _a, custodies_9, token, _b, custodies_10, custody, _c, _d, market, whitelistMeta, removeCustodyConfig, transaction, setCULimitIx, backUpOracleInstruction, addressLookupTables, result, index, res;
2033
2314
  var _e;
2034
2315
  if (userPublicKey === void 0) { userPublicKey = undefined; }
2035
2316
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
2317
+ if (whitelist === void 0) { whitelist = web3_js_1.PublicKey.default; }
2036
2318
  return __generator(this, function (_f) {
2037
2319
  switch (_f.label) {
2038
2320
  case 0:
2039
2321
  custodies = POOL_CONFIG.custodies;
2040
2322
  custodyMetas = [];
2041
2323
  marketMetas = [];
2042
- for (_a = 0, custodies_7 = custodies; _a < custodies_7.length; _a++) {
2043
- token = custodies_7[_a];
2324
+ for (_a = 0, custodies_9 = custodies; _a < custodies_9.length; _a++) {
2325
+ token = custodies_9[_a];
2044
2326
  custodyMetas.push({
2045
2327
  isSigner: false,
2046
2328
  isWritable: false,
2047
2329
  pubkey: token.custodyAccount,
2048
2330
  });
2049
2331
  }
2050
- for (_b = 0, custodies_8 = custodies; _b < custodies_8.length; _b++) {
2051
- custody = custodies_8[_b];
2332
+ for (_b = 0, custodies_10 = custodies; _b < custodies_10.length; _b++) {
2333
+ custody = custodies_10[_b];
2052
2334
  custodyMetas.push({
2053
2335
  isSigner: false,
2054
2336
  isWritable: false,
@@ -2063,12 +2345,17 @@ var PerpetualsClient = (function () {
2063
2345
  isWritable: false,
2064
2346
  });
2065
2347
  }
2348
+ whitelistMeta = {
2349
+ pubkey: whitelist,
2350
+ isSigner: false,
2351
+ isWritable: false,
2352
+ };
2066
2353
  removeCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(removeTokenCustodyKey); });
2067
2354
  return [4, this.program.methods
2068
2355
  .getRemoveLiquidityAmountAndFee({
2069
2356
  lpAmountIn: amount,
2070
2357
  })
2071
- .accounts({
2358
+ .accountsPartial({
2072
2359
  perpetuals: POOL_CONFIG.perpetuals,
2073
2360
  pool: poolKey,
2074
2361
  custody: removeTokenCustodyKey,
@@ -2076,7 +2363,7 @@ var PerpetualsClient = (function () {
2076
2363
  lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
2077
2364
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2078
2365
  })
2079
- .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2366
+ .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true), (whitelist ? [whitelistMeta] : []), true))
2080
2367
  .transaction()];
2081
2368
  case 1:
2082
2369
  transaction = _f.sent();
@@ -2088,10 +2375,13 @@ var PerpetualsClient = (function () {
2088
2375
  backUpOracleInstruction = _f.sent();
2089
2376
  (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2090
2377
  _f.label = 3;
2091
- case 3: return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2378
+ case 3: return [4, this.getOrLoadAddressLookupTable(POOL_CONFIG)];
2092
2379
  case 4:
2380
+ addressLookupTables = (_f.sent()).addressLookupTables;
2381
+ return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables, userPublicKey)];
2382
+ case 5:
2093
2383
  result = _f.sent();
2094
- index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
2384
+ index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'get_remove_liquidity_amount_and_fee'; });
2095
2385
  if (result.value.err) {
2096
2386
  console.error('error Simulation failed:', result);
2097
2387
  return [2, {
@@ -2100,7 +2390,7 @@ var PerpetualsClient = (function () {
2100
2390
  error: 'Simulation failed: ' + JSON.stringify(result.value.err),
2101
2391
  }];
2102
2392
  }
2103
- res = this.viewHelper.decodeLogs(result, index, 'getRemoveLiquidityAmountAndFee');
2393
+ res = this.viewHelper.decodeLogs(result, index, 'get_remove_liquidity_amount_and_fee');
2104
2394
  return [2, {
2105
2395
  amount: res.amount,
2106
2396
  fee: res.fee,
@@ -2109,77 +2399,17 @@ var PerpetualsClient = (function () {
2109
2399
  });
2110
2400
  });
2111
2401
  };
2112
- this.getCompoundingLPTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
2113
- var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, setCULimitIx, result, index, res;
2114
- var _d;
2115
- return __generator(this, function (_e) {
2116
- switch (_e.label) {
2117
- case 0:
2118
- backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
2119
- custodies = POOL_CONFIG.custodies;
2120
- custodyMetas = [];
2121
- marketMetas = [];
2122
- for (_i = 0, custodies_9 = custodies; _i < custodies_9.length; _i++) {
2123
- token = custodies_9[_i];
2124
- custodyMetas.push({
2125
- isSigner: false,
2126
- isWritable: false,
2127
- pubkey: token.custodyAccount,
2128
- });
2129
- }
2130
- for (_a = 0, custodies_10 = custodies; _a < custodies_10.length; _a++) {
2131
- custody = custodies_10[_a];
2132
- custodyMetas.push({
2133
- isSigner: false,
2134
- isWritable: false,
2135
- pubkey: custody.intOracleAccount,
2136
- });
2137
- }
2138
- for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
2139
- market = _c[_b];
2140
- marketMetas.push({
2141
- pubkey: market.marketAccount,
2142
- isSigner: false,
2143
- isWritable: false,
2144
- });
2145
- }
2146
- return [4, backUpOracleInstructionPromise];
2147
- case 1:
2148
- backUpOracleInstruction = _e.sent();
2149
- return [4, this.program.methods
2150
- .getCompoundingTokenPrice({})
2151
- .accounts({
2152
- perpetuals: POOL_CONFIG.perpetuals,
2153
- pool: poolKey,
2154
- lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
2155
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2156
- })
2157
- .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2158
- .transaction()];
2159
- case 2:
2160
- transaction = _e.sent();
2161
- setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2162
- transaction.instructions.unshift(setCULimitIx);
2163
- (_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
2164
- return [4, this.viewHelper.simulateTransaction(transaction)];
2165
- case 3:
2166
- result = _e.sent();
2167
- index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getCompoundingTokenPrice'; });
2168
- res = this.viewHelper.decodeLogs(result, index, 'getCompoundingTokenPrice');
2169
- return [2, res.toString()];
2170
- }
2171
- });
2172
- }); };
2173
2402
  this.getAddCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
2174
2403
  var args_1 = [];
2175
2404
  for (var _i = 4; _i < arguments.length; _i++) {
2176
2405
  args_1[_i - 4] = arguments[_i];
2177
2406
  }
2178
- 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, enableBackupOracle) {
2179
- var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
2407
+ 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, enableBackupOracle, whitelist) {
2408
+ var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, whitelistMeta, depositCustodyConfig, rewardCustody, transaction, setCULimitIx, addressLookupTables, backUpOracleInstruction, result, index, res;
2180
2409
  var _e;
2181
2410
  if (userPublicKey === void 0) { userPublicKey = undefined; }
2182
2411
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
2412
+ if (whitelist === void 0) { whitelist = web3_js_1.PublicKey.default; }
2183
2413
  return __generator(this, function (_f) {
2184
2414
  switch (_f.label) {
2185
2415
  case 0:
@@ -2210,13 +2440,18 @@ var PerpetualsClient = (function () {
2210
2440
  isWritable: false,
2211
2441
  });
2212
2442
  }
2443
+ whitelistMeta = {
2444
+ pubkey: whitelist,
2445
+ isSigner: false,
2446
+ isWritable: false,
2447
+ };
2213
2448
  depositCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(depositCustodyKey); });
2214
2449
  rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
2215
2450
  return [4, this.program.methods
2216
2451
  .getAddCompoundingLiquidityAmountAndFee({
2217
2452
  amountIn: amount,
2218
2453
  })
2219
- .accounts({
2454
+ .accountsPartial({
2220
2455
  perpetuals: POOL_CONFIG.perpetuals,
2221
2456
  pool: poolKey,
2222
2457
  inCustody: depositCustodyKey,
@@ -2227,23 +2462,26 @@ var PerpetualsClient = (function () {
2227
2462
  compoundingTokenMint: POOL_CONFIG.compoundingTokenMint,
2228
2463
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2229
2464
  })
2230
- .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2465
+ .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true), (whitelist ? [whitelistMeta] : []), true))
2231
2466
  .transaction()];
2232
2467
  case 1:
2233
2468
  transaction = _f.sent();
2234
2469
  setCULimitIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 450000 });
2235
2470
  transaction.instructions.unshift(setCULimitIx);
2236
- if (!enableBackupOracle) return [3, 3];
2237
- return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
2471
+ return [4, this.getOrLoadAddressLookupTable(POOL_CONFIG)];
2238
2472
  case 2:
2473
+ addressLookupTables = (_f.sent()).addressLookupTables;
2474
+ if (!enableBackupOracle) return [3, 4];
2475
+ return [4, (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true)];
2476
+ case 3:
2239
2477
  backUpOracleInstruction = _f.sent();
2240
2478
  (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2241
- _f.label = 3;
2242
- case 3: return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2243
- case 4:
2479
+ _f.label = 4;
2480
+ case 4: return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables, userPublicKey)];
2481
+ case 5:
2244
2482
  result = _f.sent();
2245
- index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
2246
- res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
2483
+ index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'get_add_compounding_liquidity_amount_and_fee'; });
2484
+ res = this.viewHelper.decodeLogs(result, index, 'get_add_compounding_liquidity_amount_and_fee');
2247
2485
  return [2, {
2248
2486
  amount: res.amount,
2249
2487
  fee: res.fee,
@@ -2257,11 +2495,12 @@ var PerpetualsClient = (function () {
2257
2495
  for (var _i = 4; _i < arguments.length; _i++) {
2258
2496
  args_1[_i - 4] = arguments[_i];
2259
2497
  }
2260
- 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, enableBackupOracle) {
2261
- var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, result, index, res;
2498
+ 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, enableBackupOracle, whitelist) {
2499
+ var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, whitelistMeta, removeCustodyConfig, rewardCustody, transaction, setCULimitIx, backUpOracleInstruction, addressLookupTables, result, index, res;
2262
2500
  var _e;
2263
2501
  if (userPublicKey === void 0) { userPublicKey = undefined; }
2264
2502
  if (enableBackupOracle === void 0) { enableBackupOracle = false; }
2503
+ if (whitelist === void 0) { whitelist = web3_js_1.PublicKey.default; }
2265
2504
  return __generator(this, function (_f) {
2266
2505
  switch (_f.label) {
2267
2506
  case 0:
@@ -2292,13 +2531,18 @@ var PerpetualsClient = (function () {
2292
2531
  isWritable: false,
2293
2532
  });
2294
2533
  }
2534
+ whitelistMeta = {
2535
+ pubkey: whitelist,
2536
+ isSigner: false,
2537
+ isWritable: false,
2538
+ };
2295
2539
  removeCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(removeTokenCustodyKey); });
2296
2540
  rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
2297
2541
  return [4, this.program.methods
2298
2542
  .getRemoveCompoundingLiquidityAmountAndFee({
2299
2543
  compoundingAmountIn: amount,
2300
2544
  })
2301
- .accounts({
2545
+ .accountsPartial({
2302
2546
  perpetuals: POOL_CONFIG.perpetuals,
2303
2547
  pool: poolKey,
2304
2548
  outCustody: removeTokenCustodyKey,
@@ -2309,7 +2553,7 @@ var PerpetualsClient = (function () {
2309
2553
  lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
2310
2554
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2311
2555
  })
2312
- .remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
2556
+ .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true), (whitelist ? [whitelistMeta] : []), true))
2313
2557
  .transaction()];
2314
2558
  case 1:
2315
2559
  transaction = _f.sent();
@@ -2321,17 +2565,20 @@ var PerpetualsClient = (function () {
2321
2565
  backUpOracleInstruction = _f.sent();
2322
2566
  (_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
2323
2567
  _f.label = 3;
2324
- case 3: return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
2568
+ case 3: return [4, this.getOrLoadAddressLookupTable(POOL_CONFIG)];
2325
2569
  case 4:
2570
+ addressLookupTables = (_f.sent()).addressLookupTables;
2571
+ return [4, this.viewHelper.simulateTransaction(transaction, addressLookupTables, userPublicKey)];
2572
+ case 5:
2326
2573
  result = _f.sent();
2327
- index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
2574
+ index = perpetuals_json_1.default.instructions.findIndex(function (f) { return f.name === 'get_remove_compounding_liquidity_amount_and_fee'; });
2328
2575
  if (result.value.err) {
2329
2576
  return [2, {
2330
2577
  amount: new anchor_1.BN(0),
2331
2578
  fee: new anchor_1.BN(0),
2332
2579
  }];
2333
2580
  }
2334
- res = this.viewHelper.decodeLogs(result, index, 'getRemoveCompoundingLiquidityAmountAndFee');
2581
+ res = this.viewHelper.decodeLogs(result, index, 'get_remove_compounding_liquidity_amount_and_fee');
2335
2582
  return [2, {
2336
2583
  amount: res.amount,
2337
2584
  fee: res.fee,
@@ -2357,7 +2604,7 @@ var PerpetualsClient = (function () {
2357
2604
  collateralCustodyConfig = poolConfig.custodies.find(function (f) { return f.custodyAccount.equals(marketConfig_1.collateralCustody); });
2358
2605
  return [4, this.program.methods
2359
2606
  .getLiquidationPrice({})
2360
- .accounts({
2607
+ .accountsPartial({
2361
2608
  perpetuals: this.perpetuals.publicKey,
2362
2609
  pool: poolConfig.poolAddress,
2363
2610
  position: positionAccountKey,
@@ -2391,7 +2638,7 @@ var PerpetualsClient = (function () {
2391
2638
  collateralCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(collateralMint); });
2392
2639
  return [4, this.program.methods
2393
2640
  .getLiquidationState({})
2394
- .accounts({
2641
+ .accountsPartial({
2395
2642
  perpetuals: this.perpetuals.publicKey,
2396
2643
  pool: poolConfig.poolAddress,
2397
2644
  position: positionAccount,
@@ -2441,54 +2688,7 @@ var PerpetualsClient = (function () {
2441
2688
  }
2442
2689
  return [4, this.program.methods
2443
2690
  .getCompoundingTokenData({})
2444
- .accounts({
2445
- perpetuals: this.perpetuals.publicKey,
2446
- pool: poolConfig.poolAddress,
2447
- lpTokenMint: poolConfig.stakedLpTokenMint,
2448
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
2449
- })
2450
- .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
2451
- .view()
2452
- .catch(function (err) {
2453
- console.error(err);
2454
- throw err;
2455
- })];
2456
- case 1: return [2, _d.sent()];
2457
- }
2458
- });
2459
- }); };
2460
- this.getLpTokenPriceView = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
2461
- var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market;
2462
- return __generator(this, function (_d) {
2463
- switch (_d.label) {
2464
- case 0:
2465
- custodyAccountMetas = [];
2466
- custodyOracleAccountMetas = [];
2467
- markets = [];
2468
- for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
2469
- custody = _a[_i];
2470
- custodyAccountMetas.push({
2471
- pubkey: custody.custodyAccount,
2472
- isSigner: false,
2473
- isWritable: false,
2474
- });
2475
- custodyOracleAccountMetas.push({
2476
- pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
2477
- isSigner: false,
2478
- isWritable: false,
2479
- });
2480
- }
2481
- for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
2482
- market = _c[_b];
2483
- markets.push({
2484
- pubkey: market.marketAccount,
2485
- isSigner: false,
2486
- isWritable: false,
2487
- });
2488
- }
2489
- return [4, this.program.methods
2490
- .getLpTokenPrice({})
2491
- .accounts({
2691
+ .accountsPartial({
2492
2692
  perpetuals: this.perpetuals.publicKey,
2493
2693
  pool: poolConfig.poolAddress,
2494
2694
  lpTokenMint: poolConfig.stakedLpTokenMint,
@@ -2584,7 +2784,7 @@ var PerpetualsClient = (function () {
2584
2784
  };
2585
2785
  return [4, this.program.methods
2586
2786
  .openPosition(params)
2587
- .accounts({
2787
+ .accountsPartial({
2588
2788
  owner: publicKey,
2589
2789
  feePayer: publicKey,
2590
2790
  fundingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userCollateralTokenAccount,
@@ -2599,8 +2799,6 @@ var PerpetualsClient = (function () {
2599
2799
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
2600
2800
  systemProgram: web3_js_1.SystemProgram.programId,
2601
2801
  fundingTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
2602
- eventAuthority: this.eventAuthority.publicKey,
2603
- program: this.programId,
2604
2802
  transferAuthority: this.authority.publicKey,
2605
2803
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2606
2804
  fundingMint: collateralCustodyConfig.mintKey
@@ -2685,7 +2883,7 @@ var PerpetualsClient = (function () {
2685
2883
  priceWithSlippage: priceWithSlippage,
2686
2884
  privilege: privilege
2687
2885
  })
2688
- .accounts({
2886
+ .accountsPartial({
2689
2887
  feePayer: publicKey,
2690
2888
  owner: publicKey,
2691
2889
  receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
@@ -2700,7 +2898,6 @@ var PerpetualsClient = (function () {
2700
2898
  collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
2701
2899
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
2702
2900
  eventAuthority: this.eventAuthority.publicKey,
2703
- program: this.programId,
2704
2901
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2705
2902
  collateralMint: collateralCustodyConfig.mintKey,
2706
2903
  collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
@@ -2837,7 +3034,7 @@ var PerpetualsClient = (function () {
2837
3034
  sizeAmount: sizeAmount,
2838
3035
  privilege: privilege
2839
3036
  })
2840
- .accounts({
3037
+ .accountsPartial({
2841
3038
  owner: publicKey,
2842
3039
  feePayer: publicKey,
2843
3040
  fundingAccount: userInputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
@@ -2856,7 +3053,6 @@ var PerpetualsClient = (function () {
2856
3053
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
2857
3054
  systemProgram: web3_js_1.SystemProgram.programId,
2858
3055
  eventAuthority: this.eventAuthority.publicKey,
2859
- program: this.programId,
2860
3056
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2861
3057
  fundingMint: userInputCustodyConfig.mintKey,
2862
3058
  fundingTokenProgram: poolConfig.getTokenFromSymbol(userInputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
@@ -2963,7 +3159,7 @@ var PerpetualsClient = (function () {
2963
3159
  priceWithSlippage: priceWithSlippage,
2964
3160
  privilege: privilege
2965
3161
  })
2966
- .accounts({
3162
+ .accountsPartial({
2967
3163
  owner: publicKey,
2968
3164
  feePayer: publicKey,
2969
3165
  receivingAccount: userOutputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
@@ -2981,8 +3177,6 @@ var PerpetualsClient = (function () {
2981
3177
  dispensingCustody: userOutputCustodyConfig.custodyAccount,
2982
3178
  dispensingOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
2983
3179
  dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
2984
- eventAuthority: this.eventAuthority.publicKey,
2985
- program: this.programId,
2986
3180
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
2987
3181
  receivingMint: userOutputCustodyConfig.mintKey,
2988
3182
  receivingTokenProgram: userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
@@ -3080,7 +3274,7 @@ var PerpetualsClient = (function () {
3080
3274
  _c.label = 6;
3081
3275
  case 6: return [4, this.program.methods.addCollateral({
3082
3276
  collateralDelta: collateralWithFee
3083
- }).accounts({
3277
+ }).accountsPartial({
3084
3278
  owner: publicKey,
3085
3279
  position: positionPubKey,
3086
3280
  market: marketAccount,
@@ -3092,9 +3286,7 @@ var PerpetualsClient = (function () {
3092
3286
  collateralCustody: collateralCustodyConfig.custodyAccount,
3093
3287
  collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
3094
3288
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
3095
- eventAuthority: this.eventAuthority.publicKey,
3096
3289
  fundingTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
3097
- program: this.programId,
3098
3290
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3099
3291
  fundingMint: collateralCustodyConfig.mintKey
3100
3292
  })
@@ -3194,7 +3386,7 @@ var PerpetualsClient = (function () {
3194
3386
  marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
3195
3387
  return [4, this.program.methods.swapAndAddCollateral({
3196
3388
  amountIn: amountIn,
3197
- }).accounts({
3389
+ }).accountsPartial({
3198
3390
  owner: publicKey,
3199
3391
  feePayer: publicKey,
3200
3392
  fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
@@ -3211,9 +3403,7 @@ var PerpetualsClient = (function () {
3211
3403
  collateralCustody: collateralCustodyConfig.custodyAccount,
3212
3404
  collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
3213
3405
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
3214
- eventAuthority: this.eventAuthority.publicKey,
3215
3406
  fundingTokenProgram: poolConfig.getTokenFromSymbol(inputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
3216
- program: this.programId,
3217
3407
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3218
3408
  fundingMint: poolConfig.getTokenFromSymbol(inputSymbol).mintKey,
3219
3409
  })
@@ -3300,7 +3490,7 @@ var PerpetualsClient = (function () {
3300
3490
  .removeCollateral({
3301
3491
  collateralDeltaUsd: collateralDeltaUsd,
3302
3492
  })
3303
- .accounts({
3493
+ .accountsPartial({
3304
3494
  owner: publicKey,
3305
3495
  receivingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
3306
3496
  transferAuthority: poolConfig.transferAuthority,
@@ -3315,7 +3505,6 @@ var PerpetualsClient = (function () {
3315
3505
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
3316
3506
  eventAuthority: this.eventAuthority.publicKey,
3317
3507
  receivingTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
3318
- program: this.programId,
3319
3508
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3320
3509
  receivingMint: collateralCustodyConfig.mintKey
3321
3510
  })
@@ -3404,7 +3593,7 @@ var PerpetualsClient = (function () {
3404
3593
  .removeCollateralAndSwap({
3405
3594
  collateralDeltaUsd: collateralDeltaUsd,
3406
3595
  })
3407
- .accounts({
3596
+ .accountsPartial({
3408
3597
  owner: publicKey,
3409
3598
  feePayer: publicKey,
3410
3599
  receivingAccount: outputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
@@ -3422,8 +3611,6 @@ var PerpetualsClient = (function () {
3422
3611
  dispensingCustody: outputCustodyConfig.custodyAccount,
3423
3612
  dispensingOracleAccount: this.useExtOracleAccount ? outputCustodyConfig.extOracleAccount : outputCustodyConfig.intOracleAccount,
3424
3613
  dispensingCustodyTokenAccount: outputCustodyConfig.tokenAccount,
3425
- eventAuthority: this.eventAuthority.publicKey,
3426
- program: this.programId,
3427
3614
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3428
3615
  receivingMint: outputCustodyConfig.mintKey,
3429
3616
  receivingTokenProgram: poolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
@@ -3475,7 +3662,7 @@ var PerpetualsClient = (function () {
3475
3662
  sizeDelta: sizeDelta,
3476
3663
  privilege: privilege
3477
3664
  })
3478
- .accounts({
3665
+ .accountsPartial({
3479
3666
  owner: publicKey,
3480
3667
  transferAuthority: poolConfig.transferAuthority,
3481
3668
  perpetuals: poolConfig.perpetuals,
@@ -3489,7 +3676,6 @@ var PerpetualsClient = (function () {
3489
3676
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
3490
3677
  collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
3491
3678
  eventAuthority: this.eventAuthority.publicKey,
3492
- program: this.programId,
3493
3679
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3494
3680
  collateralMint: collateralCustodyConfig.mintKey
3495
3681
  })
@@ -3539,7 +3725,7 @@ var PerpetualsClient = (function () {
3539
3725
  sizeDelta: sizeDelta,
3540
3726
  privilege: privilege
3541
3727
  })
3542
- .accounts({
3728
+ .accountsPartial({
3543
3729
  owner: publicKey,
3544
3730
  transferAuthority: poolConfig.transferAuthority,
3545
3731
  perpetuals: poolConfig.perpetuals,
@@ -3553,7 +3739,6 @@ var PerpetualsClient = (function () {
3553
3739
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
3554
3740
  collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
3555
3741
  eventAuthority: this.eventAuthority.publicKey,
3556
- program: this.programId,
3557
3742
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3558
3743
  collateralMint: collateralCustodyConfig.mintKey
3559
3744
  })
@@ -3575,10 +3760,12 @@ var PerpetualsClient = (function () {
3575
3760
  for (var _i = 4; _i < arguments.length; _i++) {
3576
3761
  args_1[_i - 4] = arguments[_i];
3577
3762
  }
3578
- return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
3579
- 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;
3763
+ return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, isWhitelistedUser, includeRemainingAccounts) {
3764
+ 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, whitelistPda, whitelistMeta, instruction, err_5;
3580
3765
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3581
3766
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3767
+ if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
3768
+ if (includeRemainingAccounts === void 0) { includeRemainingAccounts = true; }
3582
3769
  return __generator(this, function (_g) {
3583
3770
  switch (_g.label) {
3584
3771
  case 0:
@@ -3672,31 +3859,37 @@ var PerpetualsClient = (function () {
3672
3859
  throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
3673
3860
  }
3674
3861
  _g.label = 8;
3675
- case 8: return [4, this.program.methods
3676
- .addLiquidity({
3677
- amountIn: tokenAmountIn,
3678
- minLpAmountOut: minLpAmountOut
3679
- })
3680
- .accounts({
3681
- owner: publicKey,
3682
- fundingAccount: payTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userPayingTokenAccount,
3683
- lpTokenAccount: lpTokenAccount,
3684
- transferAuthority: poolConfig.transferAuthority,
3685
- perpetuals: poolConfig.perpetuals,
3686
- pool: poolConfig.poolAddress,
3687
- custody: payTokenCustodyConfig.custodyAccount,
3688
- custodyOracleAccount: this.useExtOracleAccount ? payTokenCustodyConfig.extOracleAccount : payTokenCustodyConfig.intOracleAccount,
3689
- custodyTokenAccount: payTokenCustodyConfig.tokenAccount,
3690
- lpTokenMint: poolConfig.stakedLpTokenMint,
3691
- eventAuthority: this.eventAuthority.publicKey,
3692
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3693
- program: this.programId,
3694
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3695
- fundingMint: payTokenCustodyConfig.mintKey,
3696
- fundingTokenProgram: payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
3697
- })
3698
- .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
3699
- .instruction()];
3862
+ case 8:
3863
+ whitelistPda = this.findProgramAddress("whitelist", [publicKey]).publicKey;
3864
+ whitelistMeta = {
3865
+ pubkey: whitelistPda,
3866
+ isSigner: false,
3867
+ isWritable: false,
3868
+ };
3869
+ return [4, this.program.methods
3870
+ .addLiquidity({
3871
+ amountIn: tokenAmountIn,
3872
+ minLpAmountOut: minLpAmountOut
3873
+ })
3874
+ .accountsPartial({
3875
+ owner: publicKey,
3876
+ fundingAccount: payTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userPayingTokenAccount,
3877
+ lpTokenAccount: lpTokenAccount,
3878
+ transferAuthority: poolConfig.transferAuthority,
3879
+ perpetuals: poolConfig.perpetuals,
3880
+ pool: poolConfig.poolAddress,
3881
+ custody: payTokenCustodyConfig.custodyAccount,
3882
+ custodyOracleAccount: this.useExtOracleAccount ? payTokenCustodyConfig.extOracleAccount : payTokenCustodyConfig.intOracleAccount,
3883
+ custodyTokenAccount: payTokenCustodyConfig.tokenAccount,
3884
+ lpTokenMint: poolConfig.stakedLpTokenMint,
3885
+ eventAuthority: this.eventAuthority.publicKey,
3886
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3887
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3888
+ fundingMint: payTokenCustodyConfig.mintKey,
3889
+ fundingTokenProgram: payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
3890
+ })
3891
+ .remainingAccounts(includeRemainingAccounts ? __spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true) : __spreadArray([], (isWhitelistedUser ? [whitelistMeta] : []), true))
3892
+ .instruction()];
3700
3893
  case 9:
3701
3894
  instruction = _g.sent();
3702
3895
  instructions.push(instruction);
@@ -3718,11 +3911,13 @@ var PerpetualsClient = (function () {
3718
3911
  for (var _i = 4; _i < arguments.length; _i++) {
3719
3912
  args_1[_i - 4] = arguments[_i];
3720
3913
  }
3721
- 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) {
3722
- 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;
3914
+ 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, isWhitelistedUser, includeRemainingAccounts) {
3915
+ 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, whitelistPda, whitelistMeta, instruction;
3723
3916
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
3724
3917
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3725
3918
  if (userPublicKey === void 0) { userPublicKey = undefined; }
3919
+ if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
3920
+ if (includeRemainingAccounts === void 0) { includeRemainingAccounts = true; }
3726
3921
  return __generator(this, function (_g) {
3727
3922
  switch (_g.label) {
3728
3923
  case 0:
@@ -3814,10 +4009,16 @@ var PerpetualsClient = (function () {
3814
4009
  isWritable: false,
3815
4010
  });
3816
4011
  }
4012
+ whitelistPda = this.findProgramAddress("whitelist", [publicKey]).publicKey;
4013
+ whitelistMeta = {
4014
+ pubkey: whitelistPda,
4015
+ isSigner: false,
4016
+ isWritable: false,
4017
+ };
3817
4018
  return [4, this.program.methods.addLiquidityAndStake({
3818
4019
  amountIn: amountIn,
3819
4020
  minLpAmountOut: minLpAmountOut,
3820
- }).accounts({
4021
+ }).accountsPartial({
3821
4022
  owner: publicKey,
3822
4023
  feePayer: publicKey,
3823
4024
  fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
@@ -3832,13 +4033,11 @@ var PerpetualsClient = (function () {
3832
4033
  poolStakedLpVault: poolStakedLpVault,
3833
4034
  systemProgram: web3_js_1.SystemProgram.programId,
3834
4035
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3835
- eventAuthority: this.eventAuthority.publicKey,
3836
- program: this.programId,
3837
4036
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3838
4037
  fundingMint: inputCustodyConfig.mintKey,
3839
- fundingTokenProgram: inputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
4038
+ fundingTokenProgram: inputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
3840
4039
  })
3841
- .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4040
+ .remainingAccounts(includeRemainingAccounts ? __spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true) : __spreadArray([], (isWhitelistedUser ? [whitelistMeta] : []), true))
3842
4041
  .instruction()];
3843
4042
  case 8:
3844
4043
  instruction = _g.sent();
@@ -3856,13 +4055,15 @@ var PerpetualsClient = (function () {
3856
4055
  for (var _i = 4; _i < arguments.length; _i++) {
3857
4056
  args_1[_i - 4] = arguments[_i];
3858
4057
  }
3859
- 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) {
3860
- 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;
4058
+ 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, isWhitelistedUser, includeRemainingAccounts) {
4059
+ var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, recieveToken, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, _e, whitelistPda, whitelistMeta, removeLiquidityTx, closeInx, closeWsolATAIns, err_6;
3861
4060
  if (closeLpATA === void 0) { closeLpATA = false; }
3862
4061
  if (createUserATA === void 0) { createUserATA = true; }
3863
4062
  if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
3864
4063
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
3865
4064
  if (userPublicKey === void 0) { userPublicKey = undefined; }
4065
+ if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
4066
+ if (includeRemainingAccounts === void 0) { includeRemainingAccounts = true; }
3866
4067
  return __generator(this, function (_f) {
3867
4068
  switch (_f.label) {
3868
4069
  case 0:
@@ -3937,31 +4138,37 @@ var PerpetualsClient = (function () {
3937
4138
  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));
3938
4139
  }
3939
4140
  _f.label = 5;
3940
- case 5: return [4, this.program.methods
3941
- .removeLiquidity({
3942
- lpAmountIn: liquidityAmountIn,
3943
- minAmountOut: minTokenAmountOut
3944
- })
3945
- .accounts({
3946
- owner: publicKey,
3947
- receivingAccount: recieveTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
3948
- lpTokenAccount: stakedLpTokenAccount,
3949
- transferAuthority: poolConfig.transferAuthority,
3950
- perpetuals: poolConfig.perpetuals,
3951
- pool: poolConfig.poolAddress,
3952
- custody: recieveTokenCustodyConfig.custodyAccount,
3953
- custodyOracleAccount: this.useExtOracleAccount ? recieveTokenCustodyConfig.extOracleAccount : recieveTokenCustodyConfig.intOracleAccount,
3954
- custodyTokenAccount: recieveTokenCustodyConfig.tokenAccount,
3955
- lpTokenMint: poolConfig.stakedLpTokenMint,
3956
- eventAuthority: this.eventAuthority.publicKey,
3957
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
3958
- program: this.programId,
3959
- ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
3960
- receivingMint: recieveTokenCustodyConfig.mintKey,
3961
- receivingTokenProgram: recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
3962
- })
3963
- .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
3964
- .instruction()];
4141
+ case 5:
4142
+ whitelistPda = this.findProgramAddress("whitelist", [publicKey]).publicKey;
4143
+ whitelistMeta = {
4144
+ pubkey: whitelistPda,
4145
+ isSigner: false,
4146
+ isWritable: false,
4147
+ };
4148
+ return [4, this.program.methods
4149
+ .removeLiquidity({
4150
+ lpAmountIn: liquidityAmountIn,
4151
+ minAmountOut: minTokenAmountOut
4152
+ })
4153
+ .accountsPartial({
4154
+ owner: publicKey,
4155
+ receivingAccount: recieveTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
4156
+ lpTokenAccount: stakedLpTokenAccount,
4157
+ transferAuthority: poolConfig.transferAuthority,
4158
+ perpetuals: poolConfig.perpetuals,
4159
+ pool: poolConfig.poolAddress,
4160
+ custody: recieveTokenCustodyConfig.custodyAccount,
4161
+ custodyOracleAccount: this.useExtOracleAccount ? recieveTokenCustodyConfig.extOracleAccount : recieveTokenCustodyConfig.intOracleAccount,
4162
+ custodyTokenAccount: recieveTokenCustodyConfig.tokenAccount,
4163
+ lpTokenMint: poolConfig.stakedLpTokenMint,
4164
+ eventAuthority: this.eventAuthority.publicKey,
4165
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4166
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4167
+ receivingMint: recieveTokenCustodyConfig.mintKey,
4168
+ receivingTokenProgram: recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
4169
+ })
4170
+ .remainingAccounts(includeRemainingAccounts ? __spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true) : __spreadArray([], (isWhitelistedUser ? [whitelistMeta] : []), true))
4171
+ .instruction()];
3965
4172
  case 6:
3966
4173
  removeLiquidityTx = _f.sent();
3967
4174
  instructions.push(removeLiquidityTx);
@@ -4001,7 +4208,7 @@ var PerpetualsClient = (function () {
4001
4208
  _a.trys.push([1, 3, , 4]);
4002
4209
  return [4, this.program.methods
4003
4210
  .createReferral({})
4004
- .accounts({
4211
+ .accountsPartial({
4005
4212
  owner: publicKey,
4006
4213
  feePayer: publicKey,
4007
4214
  referralAccount: nftReferralAccount,
@@ -4046,7 +4253,7 @@ var PerpetualsClient = (function () {
4046
4253
  .depositStake({
4047
4254
  depositAmount: depositAmount
4048
4255
  })
4049
- .accounts({
4256
+ .accountsPartial({
4050
4257
  owner: owner,
4051
4258
  feePayer: feePayer,
4052
4259
  fundingLpTokenAccount: userLpTokenAccount,
@@ -4057,8 +4264,6 @@ var PerpetualsClient = (function () {
4057
4264
  poolStakedLpVault: poolStakedLpVault,
4058
4265
  systemProgram: web3_js_1.SystemProgram.programId,
4059
4266
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4060
- eventAuthority: this.eventAuthority.publicKey,
4061
- program: this.programId,
4062
4267
  lpTokenMint: poolConfig.stakedLpTokenMint,
4063
4268
  })
4064
4269
  .instruction()];
@@ -4111,12 +4316,11 @@ var PerpetualsClient = (function () {
4111
4316
  }
4112
4317
  return [4, this.program.methods
4113
4318
  .refreshStake({})
4114
- .accounts({
4319
+ .accountsPartial({
4115
4320
  perpetuals: this.perpetuals.publicKey,
4116
4321
  pool: pool,
4117
4322
  rewardCustody: rewardCustodyConfig.custodyAccount,
4118
4323
  feeDistributionTokenAccount: feeDistributionTokenAccount,
4119
- eventAuthority: this.eventAuthority.publicKey,
4120
4324
  program: this.program.programId,
4121
4325
  })
4122
4326
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), flpStakeAccountMetas, true))
@@ -4172,12 +4376,11 @@ var PerpetualsClient = (function () {
4172
4376
  });
4173
4377
  return [4, this.program.methods
4174
4378
  .refreshStake({})
4175
- .accounts({
4379
+ .accountsPartial({
4176
4380
  perpetuals: this.perpetuals.publicKey,
4177
4381
  pool: pool,
4178
4382
  rewardCustody: rewardCustodyConfig.custodyAccount,
4179
4383
  feeDistributionTokenAccount: feeDistributionTokenAccount,
4180
- eventAuthority: this.eventAuthority.publicKey,
4181
4384
  program: this.program.programId,
4182
4385
  })
4183
4386
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
@@ -4236,13 +4439,12 @@ var PerpetualsClient = (function () {
4236
4439
  .unstakeInstant({
4237
4440
  unstakeAmount: unstakeAmount
4238
4441
  })
4239
- .accounts({
4442
+ .accountsPartial({
4240
4443
  owner: publicKey,
4241
4444
  perpetuals: this.perpetuals.publicKey,
4242
4445
  pool: pool,
4243
4446
  flpStakeAccount: flpStakeAccount,
4244
4447
  rewardCustody: rewardCustodyConfig.custodyAccount,
4245
- eventAuthority: this.eventAuthority.publicKey,
4246
4448
  program: this.program.programId,
4247
4449
  })
4248
4450
  .remainingAccounts(__spreadArray([], tokenStakeAccounts, true))
@@ -4297,7 +4499,7 @@ var PerpetualsClient = (function () {
4297
4499
  .setFeeShare({
4298
4500
  feeShareBps: new anchor_1.BN(7000)
4299
4501
  })
4300
- .accounts({
4502
+ .accountsPartial({
4301
4503
  admin: publicKey,
4302
4504
  multisig: this.multisig.publicKey,
4303
4505
  pool: pool,
@@ -4334,14 +4536,13 @@ var PerpetualsClient = (function () {
4334
4536
  .unstakeRequest({
4335
4537
  unstakeAmount: unstakeAmount
4336
4538
  })
4337
- .accounts({
4539
+ .accountsPartial({
4338
4540
  owner: publicKey,
4339
4541
  perpetuals: this.perpetuals.publicKey,
4340
4542
  pool: pool,
4341
4543
  flpStakeAccount: flpStakeAccount,
4342
4544
  systemProgram: web3_js_1.SystemProgram.programId,
4343
4545
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4344
- eventAuthority: this.eventAuthority.publicKey,
4345
4546
  program: this.programId
4346
4547
  })
4347
4548
  .instruction()];
@@ -4402,7 +4603,7 @@ var PerpetualsClient = (function () {
4402
4603
  pendingActivation: pendingActivation,
4403
4604
  deactivated: deactivated
4404
4605
  })
4405
- .accounts({
4606
+ .accountsPartial({
4406
4607
  owner: publicKey,
4407
4608
  receivingLpTokenAccount: userLpTokenAccount,
4408
4609
  transferAuthority: poolConfig.transferAuthority,
@@ -4412,7 +4613,6 @@ var PerpetualsClient = (function () {
4412
4613
  poolStakedLpVault: poolStakedLpVault,
4413
4614
  systemProgram: web3_js_1.SystemProgram.programId,
4414
4615
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4415
- eventAuthority: this.eventAuthority.publicKey,
4416
4616
  program: this.program.programId,
4417
4617
  lpMint: poolConfig.stakedLpTokenMint,
4418
4618
  })
@@ -4477,7 +4677,7 @@ var PerpetualsClient = (function () {
4477
4677
  }
4478
4678
  return [4, this.program.methods
4479
4679
  .collectStakeFees({})
4480
- .accounts({
4680
+ .accountsPartial({
4481
4681
  owner: publicKey,
4482
4682
  receivingTokenAccount: receivingTokenAccount,
4483
4683
  transferAuthority: poolConfig.transferAuthority,
@@ -4489,7 +4689,6 @@ var PerpetualsClient = (function () {
4489
4689
  program: this.program.programId,
4490
4690
  systemProgram: web3_js_1.SystemProgram.programId,
4491
4691
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4492
- eventAuthority: this.eventAuthority.publicKey,
4493
4692
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4494
4693
  receivingMint: rewardCustodyMint,
4495
4694
  })
@@ -4516,13 +4715,14 @@ var PerpetualsClient = (function () {
4516
4715
  for (var _i = 5; _i < arguments.length; _i++) {
4517
4716
  args_1[_i - 5] = arguments[_i];
4518
4717
  }
4519
- 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, enableHeapSizeIx, enableDebugLogs) {
4520
- 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, heapSizeIx, addCompoundingLiquidity, err_16;
4718
+ 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, enableHeapSizeIx, isWhitelistedUser, includeRemainingAccounts) {
4719
+ 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, heapSizeIx, whitelistPda, whitelistMeta, addCompoundingLiquidity, err_16;
4521
4720
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
4522
4721
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4523
4722
  if (userPublicKey === void 0) { userPublicKey = undefined; }
4524
4723
  if (enableHeapSizeIx === void 0) { enableHeapSizeIx = true; }
4525
- if (enableDebugLogs === void 0) { enableDebugLogs = false; }
4724
+ if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
4725
+ if (includeRemainingAccounts === void 0) { includeRemainingAccounts = true; }
4526
4726
  return __generator(this, function (_f) {
4527
4727
  switch (_f.label) {
4528
4728
  case 0:
@@ -4617,17 +4817,20 @@ var PerpetualsClient = (function () {
4617
4817
  heapSizeIx = web3_js_1.ComputeBudgetProgram.requestHeapFrame({
4618
4818
  bytes: 64 * 1024,
4619
4819
  });
4620
- if (enableDebugLogs) {
4621
- console.log("SDK: adding 64 liq Data heapSizeIx for addCompoundingLiquidity");
4622
- }
4623
4820
  preInstructions.push(heapSizeIx);
4624
4821
  }
4822
+ whitelistPda = this.findProgramAddress("whitelist", [publicKey]).publicKey;
4823
+ whitelistMeta = {
4824
+ pubkey: whitelistPda,
4825
+ isSigner: false,
4826
+ isWritable: false,
4827
+ };
4625
4828
  return [4, this.program.methods
4626
4829
  .addCompoundingLiquidity({
4627
4830
  amountIn: amountIn,
4628
4831
  minCompoundingAmountOut: minCompoundingAmountOut
4629
4832
  })
4630
- .accounts({
4833
+ .accountsPartial({
4631
4834
  owner: publicKey,
4632
4835
  fundingAccount: inTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : fundingAccount,
4633
4836
  compoundingTokenAccount: compoundingTokenAccount,
@@ -4643,13 +4846,12 @@ var PerpetualsClient = (function () {
4643
4846
  lpTokenMint: lpTokenMint,
4644
4847
  compoundingTokenMint: compoundingTokenMint,
4645
4848
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4646
- eventAuthority: this.eventAuthority.publicKey,
4647
4849
  program: this.program.programId,
4648
4850
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4649
4851
  fundingMint: inCustodyConfig.mintKey,
4650
4852
  fundingTokenProgram: poolConfig.getTokenFromSymbol(inTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
4651
4853
  })
4652
- .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4854
+ .remainingAccounts(includeRemainingAccounts ? __spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true) : __spreadArray([], (isWhitelistedUser ? [whitelistMeta] : []), true))
4653
4855
  .instruction()];
4654
4856
  case 8:
4655
4857
  addCompoundingLiquidity = _f.sent();
@@ -4672,13 +4874,14 @@ var PerpetualsClient = (function () {
4672
4874
  for (var _i = 5; _i < arguments.length; _i++) {
4673
4875
  args_1[_i - 5] = arguments[_i];
4674
4876
  }
4675
- 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, enableHeapSizeIx, enableDebugLogs) {
4676
- var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, heapSizeIx, removeCompoundingLiquidity, err_17;
4877
+ 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, enableHeapSizeIx, isWhitelistedUser, includeRemainingAccounts) {
4878
+ var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, heapSizeIx, whitelistPda, whitelistMeta, removeCompoundingLiquidity, err_17;
4677
4879
  if (createUserATA === void 0) { createUserATA = true; }
4678
4880
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
4679
4881
  if (userPublicKey === void 0) { userPublicKey = undefined; }
4680
4882
  if (enableHeapSizeIx === void 0) { enableHeapSizeIx = true; }
4681
- if (enableDebugLogs === void 0) { enableDebugLogs = false; }
4883
+ if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
4884
+ if (includeRemainingAccounts === void 0) { includeRemainingAccounts = true; }
4682
4885
  return __generator(this, function (_f) {
4683
4886
  switch (_f.label) {
4684
4887
  case 0:
@@ -4757,17 +4960,20 @@ var PerpetualsClient = (function () {
4757
4960
  heapSizeIx = web3_js_1.ComputeBudgetProgram.requestHeapFrame({
4758
4961
  bytes: 64 * 1024,
4759
4962
  });
4760
- if (enableDebugLogs) {
4761
- console.log("SDK: adding 64 liq Data heapSizeIx for addCompoundingLiquidity");
4762
- }
4763
4963
  preInstructions.push(heapSizeIx);
4764
4964
  }
4965
+ whitelistPda = this.findProgramAddress("whitelist", [publicKey]).publicKey;
4966
+ whitelistMeta = {
4967
+ pubkey: whitelistPda,
4968
+ isSigner: false,
4969
+ isWritable: false,
4970
+ };
4765
4971
  return [4, this.program.methods
4766
4972
  .removeCompoundingLiquidity({
4767
4973
  compoundingAmountIn: compoundingAmountIn,
4768
4974
  minAmountOut: minAmountOut
4769
4975
  })
4770
- .accounts({
4976
+ .accountsPartial({
4771
4977
  owner: publicKey,
4772
4978
  receivingAccount: outCustodyConfig.symbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
4773
4979
  compoundingTokenAccount: compoundingTokenAccount,
@@ -4783,13 +4989,12 @@ var PerpetualsClient = (function () {
4783
4989
  lpTokenMint: lpTokenMint,
4784
4990
  compoundingTokenMint: compoundingTokenMint,
4785
4991
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4786
- eventAuthority: this.eventAuthority.publicKey,
4787
4992
  program: this.program.programId,
4788
4993
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
4789
4994
  receivingMint: outCustodyConfig.mintKey,
4790
- receivingTokenProgram: poolConfig.getTokenFromSymbol(outTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
4995
+ receivingTokenProgram: poolConfig.getTokenFromSymbol(outTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
4791
4996
  })
4792
- .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
4997
+ .remainingAccounts(includeRemainingAccounts ? __spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), (isWhitelistedUser ? [whitelistMeta] : []), true) : __spreadArray([], (isWhitelistedUser ? [whitelistMeta] : []), true))
4793
4998
  .instruction()];
4794
4999
  case 6:
4795
5000
  removeCompoundingLiquidity = _f.sent();
@@ -4886,7 +5091,7 @@ var PerpetualsClient = (function () {
4886
5091
  .migrateStake({
4887
5092
  amount: amount
4888
5093
  })
4889
- .accounts({
5094
+ .accountsPartial({
4890
5095
  owner: publicKey,
4891
5096
  compoundingTokenAccount: compoudingTokenAccount,
4892
5097
  transferAuthority: poolConfig.transferAuthority,
@@ -4900,7 +5105,6 @@ var PerpetualsClient = (function () {
4900
5105
  lpTokenMint: lpTokenMint,
4901
5106
  compoundingTokenMint: compoundingTokenMint,
4902
5107
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4903
- eventAuthority: this.eventAuthority.publicKey,
4904
5108
  program: this.program.programId,
4905
5109
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
4906
5110
  })
@@ -4969,7 +5173,7 @@ var PerpetualsClient = (function () {
4969
5173
  .migrateFlp({
4970
5174
  compoundingTokenAmount: amount
4971
5175
  })
4972
- .accounts({
5176
+ .accountsPartial({
4973
5177
  owner: publicKey,
4974
5178
  compoundingTokenAccount: compoudingTokenAccount,
4975
5179
  transferAuthority: poolConfig.transferAuthority,
@@ -4984,7 +5188,6 @@ var PerpetualsClient = (function () {
4984
5188
  compoundingTokenMint: compoundingTokenMint,
4985
5189
  systemProgram: web3_js_1.SystemProgram.programId,
4986
5190
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
4987
- eventAuthority: this.eventAuthority.publicKey,
4988
5191
  program: this.program.programId,
4989
5192
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
4990
5193
  })
@@ -5049,7 +5252,7 @@ var PerpetualsClient = (function () {
5049
5252
  _e.trys.push([1, 3, , 4]);
5050
5253
  return [4, this.program.methods
5051
5254
  .compoundFees({})
5052
- .accounts({
5255
+ .accountsPartial({
5053
5256
  poolCompoundingLpVault: poolConfig.compoundingLpVault,
5054
5257
  transferAuthority: poolConfig.transferAuthority,
5055
5258
  perpetuals: poolConfig.perpetuals,
@@ -5058,7 +5261,6 @@ var PerpetualsClient = (function () {
5058
5261
  rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
5059
5262
  lpTokenMint: lpTokenMint,
5060
5263
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5061
- eventAuthority: this.eventAuthority.publicKey,
5062
5264
  program: this.program.programId,
5063
5265
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5064
5266
  })
@@ -5103,7 +5305,7 @@ var PerpetualsClient = (function () {
5103
5305
  .depositTokenStake({
5104
5306
  depositAmount: depositAmount
5105
5307
  })
5106
- .accounts({
5308
+ .accountsPartial({
5107
5309
  owner: owner,
5108
5310
  feePayer: feePayer,
5109
5311
  fundingTokenAccount: userTokenAccount,
@@ -5113,8 +5315,6 @@ var PerpetualsClient = (function () {
5113
5315
  tokenStakeAccount: tokenStakeAccount,
5114
5316
  systemProgram: web3_js_1.SystemProgram.programId,
5115
5317
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5116
- eventAuthority: this.eventAuthority.publicKey,
5117
- program: this.programId,
5118
5318
  tokenMint: poolConfig.tokenMint,
5119
5319
  })
5120
5320
  .instruction()];
@@ -5150,11 +5350,10 @@ var PerpetualsClient = (function () {
5150
5350
  .unstakeTokenRequest({
5151
5351
  unstakeAmount: unstakeAmount
5152
5352
  })
5153
- .accounts({
5353
+ .accountsPartial({
5154
5354
  owner: owner,
5155
5355
  tokenVault: poolConfig.tokenVault,
5156
5356
  tokenStakeAccount: tokenStakeAccount,
5157
- eventAuthority: this.eventAuthority.publicKey,
5158
5357
  program: this.programId
5159
5358
  })
5160
5359
  .instruction()];
@@ -5196,7 +5395,7 @@ var PerpetualsClient = (function () {
5196
5395
  .unstakeTokenInstant({
5197
5396
  unstakeAmount: unstakeAmount
5198
5397
  })
5199
- .accounts({
5398
+ .accountsPartial({
5200
5399
  owner: owner,
5201
5400
  receivingTokenAccount: userTokenAccount,
5202
5401
  perpetuals: poolConfig.perpetuals,
@@ -5205,8 +5404,6 @@ var PerpetualsClient = (function () {
5205
5404
  tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
5206
5405
  tokenStakeAccount: tokenStakeAccount,
5207
5406
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5208
- eventAuthority: this.eventAuthority.publicKey,
5209
- program: this.programId,
5210
5407
  tokenMint: poolConfig.tokenMint,
5211
5408
  })
5212
5409
  .instruction()];
@@ -5248,7 +5445,7 @@ var PerpetualsClient = (function () {
5248
5445
  .withdrawToken({
5249
5446
  withdrawRequestId: withdrawRequestId
5250
5447
  })
5251
- .accounts({
5448
+ .accountsPartial({
5252
5449
  owner: owner,
5253
5450
  receivingTokenAccount: userTokenAccount,
5254
5451
  perpetuals: this.perpetuals.publicKey,
@@ -5257,8 +5454,6 @@ var PerpetualsClient = (function () {
5257
5454
  tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
5258
5455
  tokenStakeAccount: tokenStakeAccount,
5259
5456
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5260
- eventAuthority: this.eventAuthority.publicKey,
5261
- program: this.programId,
5262
5457
  tokenMint: poolConfig.tokenMint,
5263
5458
  })
5264
5459
  .instruction()];
@@ -5294,11 +5489,10 @@ var PerpetualsClient = (function () {
5294
5489
  .cancelUnstakeTokenRequest({
5295
5490
  withdrawRequestId: withdrawRequestId
5296
5491
  })
5297
- .accounts({
5492
+ .accountsPartial({
5298
5493
  owner: owner,
5299
5494
  tokenVault: poolConfig.tokenVault,
5300
5495
  tokenStakeAccount: tokenStakeAccount,
5301
- eventAuthority: this.eventAuthority.publicKey,
5302
5496
  program: this.programId
5303
5497
  })
5304
5498
  .instruction()];
@@ -5350,7 +5544,7 @@ var PerpetualsClient = (function () {
5350
5544
  }
5351
5545
  return [4, this.program.methods
5352
5546
  .collectTokenReward({})
5353
- .accounts({
5547
+ .accountsPartial({
5354
5548
  owner: owner,
5355
5549
  receivingTokenAccount: userTokenAccount,
5356
5550
  perpetuals: this.perpetuals.publicKey,
@@ -5359,8 +5553,6 @@ var PerpetualsClient = (function () {
5359
5553
  tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
5360
5554
  tokenStakeAccount: tokenStakeAccount,
5361
5555
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5362
- eventAuthority: this.eventAuthority.publicKey,
5363
- program: this.programId,
5364
5556
  tokenMint: poolConfig.tokenMint,
5365
5557
  })
5366
5558
  .instruction()];
@@ -5414,7 +5606,7 @@ var PerpetualsClient = (function () {
5414
5606
  }
5415
5607
  return [4, this.program.methods
5416
5608
  .collectRevenue({})
5417
- .accounts({
5609
+ .accountsPartial({
5418
5610
  owner: owner,
5419
5611
  receivingRevenueAccount: userTokenAccount,
5420
5612
  perpetuals: this.perpetuals.publicKey,
@@ -5423,8 +5615,6 @@ var PerpetualsClient = (function () {
5423
5615
  revenueTokenAccount: poolConfig.revenueTokenAccount,
5424
5616
  tokenStakeAccount: tokenStakeAccount,
5425
5617
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5426
- eventAuthority: this.eventAuthority.publicKey,
5427
- program: this.programId,
5428
5618
  receivingTokenMint: rewardCustodyMint,
5429
5619
  })
5430
5620
  .instruction()];
@@ -5478,7 +5668,7 @@ var PerpetualsClient = (function () {
5478
5668
  }
5479
5669
  return [4, this.program.methods
5480
5670
  .collectRebate()
5481
- .accounts({
5671
+ .accountsPartial({
5482
5672
  owner: owner,
5483
5673
  receivingTokenAccount: userTokenAccount,
5484
5674
  perpetuals: this.perpetuals.publicKey,
@@ -5487,8 +5677,6 @@ var PerpetualsClient = (function () {
5487
5677
  rebateTokenAccount: poolConfig.rebateTokenAccount,
5488
5678
  tokenStakeAccount: tokenStakeAccount,
5489
5679
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5490
- eventAuthority: this.eventAuthority.publicKey,
5491
- program: this.programId,
5492
5680
  receivingTokenMint: rebateMint,
5493
5681
  })
5494
5682
  .instruction()];
@@ -5524,7 +5712,7 @@ var PerpetualsClient = (function () {
5524
5712
  rebateMint = poolConfig.getTokenFromSymbol(rebateSymbol).mintKey;
5525
5713
  return [4, this.program.methods
5526
5714
  .settleRebates()
5527
- .accounts({
5715
+ .accountsPartial({
5528
5716
  transferAuthority: poolConfig.transferAuthority,
5529
5717
  perpetuals: this.perpetuals.publicKey,
5530
5718
  pool: poolConfig.poolAddress,
@@ -5535,8 +5723,6 @@ var PerpetualsClient = (function () {
5535
5723
  rebateTokenAccount: poolConfig.rebateTokenAccount,
5536
5724
  tokenMint: rebateMint,
5537
5725
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
5538
- eventAuthority: this.eventAuthority.publicKey,
5539
- program: this.programId,
5540
5726
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5541
5727
  })
5542
5728
  .instruction()];
@@ -5639,7 +5825,7 @@ var PerpetualsClient = (function () {
5639
5825
  stopLossPrice: stopLossPrice,
5640
5826
  takeProfitPrice: takeProfitPrice
5641
5827
  })
5642
- .accounts({
5828
+ .accountsPartial({
5643
5829
  owner: publicKey,
5644
5830
  feePayer: publicKey,
5645
5831
  fundingAccount: reserveSymbol == 'SOL' ? wrappedSolAccount.publicKey : userReserveTokenAccount,
@@ -5656,8 +5842,6 @@ var PerpetualsClient = (function () {
5656
5842
  receiveCustody: receiveCustodyConfig.custodyAccount,
5657
5843
  systemProgram: web3_js_1.SystemProgram.programId,
5658
5844
  fundingTokenProgram: poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
5659
- eventAuthority: this.eventAuthority.publicKey,
5660
- program: this.programId,
5661
5845
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
5662
5846
  fundingMint: reserveCustodyConfig.mintKey,
5663
5847
  })
@@ -5747,7 +5931,7 @@ var PerpetualsClient = (function () {
5747
5931
  stopLossPrice: stopLossPrice,
5748
5932
  takeProfitPrice: takeProfitPrice
5749
5933
  })
5750
- .accounts({
5934
+ .accountsPartial({
5751
5935
  owner: publicKey,
5752
5936
  feePayer: publicKey,
5753
5937
  receivingAccount: reserveSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
@@ -5764,8 +5948,6 @@ var PerpetualsClient = (function () {
5764
5948
  reserveCustodyTokenAccount: reserveCustodyConfig.tokenAccount,
5765
5949
  receiveCustody: receiveCustodyConfig.custodyAccount,
5766
5950
  receivingTokenProgram: poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
5767
- eventAuthority: this.eventAuthority.publicKey,
5768
- program: this.programId,
5769
5951
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
5770
5952
  receivingMint: poolConfig.getTokenFromSymbol(reserveSymbol).mintKey
5771
5953
  })
@@ -5816,7 +5998,7 @@ var PerpetualsClient = (function () {
5816
5998
  orderId: orderId,
5817
5999
  privilege: privilege
5818
6000
  })
5819
- .accounts({
6001
+ .accountsPartial({
5820
6002
  positionOwner: userPubkey,
5821
6003
  feePayer: publicKey,
5822
6004
  transferAuthority: poolConfig.transferAuthority,
@@ -5832,8 +6014,6 @@ var PerpetualsClient = (function () {
5832
6014
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
5833
6015
  systemProgram: web3_js_1.SystemProgram.programId,
5834
6016
  collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
5835
- eventAuthority: this.eventAuthority.publicKey,
5836
- program: this.programId,
5837
6017
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
5838
6018
  collateralMint: collateralCustodyConfig.mintKey,
5839
6019
  })
@@ -5886,7 +6066,7 @@ var PerpetualsClient = (function () {
5886
6066
  orderId: orderId,
5887
6067
  privilege: privilege
5888
6068
  })
5889
- .accounts({
6069
+ .accountsPartial({
5890
6070
  positionOwner: userPubkey,
5891
6071
  feePayer: publicKey,
5892
6072
  transferAuthority: poolConfig.transferAuthority,
@@ -5904,8 +6084,6 @@ var PerpetualsClient = (function () {
5904
6084
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
5905
6085
  systemProgram: web3_js_1.SystemProgram.programId,
5906
6086
  collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
5907
- eventAuthority: this.eventAuthority.publicKey,
5908
- program: this.programId,
5909
6087
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
5910
6088
  collateralMint: collateralCustodyConfig.mintKey,
5911
6089
  })
@@ -5952,7 +6130,7 @@ var PerpetualsClient = (function () {
5952
6130
  deltaSizeAmount: deltaSizeAmount,
5953
6131
  isStopLoss: isStopLoss
5954
6132
  })
5955
- .accounts({
6133
+ .accountsPartial({
5956
6134
  owner: publicKey,
5957
6135
  feePayer: publicKey,
5958
6136
  perpetuals: poolConfig.perpetuals,
@@ -5966,8 +6144,6 @@ var PerpetualsClient = (function () {
5966
6144
  collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
5967
6145
  receiveCustody: receivingCustodyConfig.custodyAccount,
5968
6146
  systemProgram: web3_js_1.SystemProgram.programId,
5969
- eventAuthority: this.eventAuthority.publicKey,
5970
- program: this.programId,
5971
6147
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
5972
6148
  })
5973
6149
  .instruction()];
@@ -6012,7 +6188,7 @@ var PerpetualsClient = (function () {
6012
6188
  deltaSizeAmount: deltaSizeAmount,
6013
6189
  isStopLoss: isStopLoss
6014
6190
  })
6015
- .accounts({
6191
+ .accountsPartial({
6016
6192
  owner: publicKey,
6017
6193
  perpetuals: poolConfig.perpetuals,
6018
6194
  pool: poolConfig.poolAddress,
@@ -6024,8 +6200,6 @@ var PerpetualsClient = (function () {
6024
6200
  collateralCustody: collateralCustodyConfig.custodyAccount,
6025
6201
  collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
6026
6202
  receiveCustody: receivingCustodyConfig.custodyAccount,
6027
- eventAuthority: this.eventAuthority.publicKey,
6028
- program: this.programId,
6029
6203
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
6030
6204
  })
6031
6205
  .instruction()];
@@ -6066,11 +6240,9 @@ var PerpetualsClient = (function () {
6066
6240
  orderId: orderId,
6067
6241
  isStopLoss: isStopLoss
6068
6242
  })
6069
- .accounts({
6243
+ .accountsPartial({
6070
6244
  owner: publicKey,
6071
6245
  order: orderAccount,
6072
- eventAuthority: this.eventAuthority.publicKey,
6073
- program: this.programId,
6074
6246
  })
6075
6247
  .instruction()];
6076
6248
  case 2:
@@ -6108,11 +6280,9 @@ var PerpetualsClient = (function () {
6108
6280
  positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
6109
6281
  return [4, this.program.methods
6110
6282
  .cancelAllTriggerOrders()
6111
- .accounts({
6283
+ .accountsPartial({
6112
6284
  position: positionAccount,
6113
6285
  order: orderAccount,
6114
- eventAuthority: this.eventAuthority.publicKey,
6115
- program: this.programId,
6116
6286
  })
6117
6287
  .instruction()];
6118
6288
  case 2:
@@ -6208,7 +6378,7 @@ var PerpetualsClient = (function () {
6208
6378
  orderId: orderId,
6209
6379
  privilege: privilege
6210
6380
  })
6211
- .accounts({
6381
+ .accountsPartial({
6212
6382
  positionOwner: owner,
6213
6383
  feePayer: payerPubkey,
6214
6384
  receivingAccount: userReceivingTokenAccount,
@@ -6227,8 +6397,6 @@ var PerpetualsClient = (function () {
6227
6397
  dispensingCustody: receivingCustodyConfig.custodyAccount,
6228
6398
  dispensingOracleAccount: this.useExtOracleAccount ? receivingCustodyConfig.extOracleAccount : receivingCustodyConfig.intOracleAccount,
6229
6399
  dispensingCustodyTokenAccount: receivingCustodyConfig.tokenAccount,
6230
- eventAuthority: this.eventAuthority.publicKey,
6231
- program: this.programId,
6232
6400
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
6233
6401
  receivingMint: receivingCustodyConfig.mintKey,
6234
6402
  receivingTokenProgram: receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
@@ -6302,7 +6470,7 @@ var PerpetualsClient = (function () {
6302
6470
  orderId: orderId,
6303
6471
  privilege: privilege
6304
6472
  })
6305
- .accounts({
6473
+ .accountsPartial({
6306
6474
  feePayer: payerPubkey,
6307
6475
  positionOwner: owner,
6308
6476
  receivingAccount: userReceivingTokenAccount,
@@ -6318,8 +6486,6 @@ var PerpetualsClient = (function () {
6318
6486
  collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
6319
6487
  collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
6320
6488
  receivingTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
6321
- eventAuthority: this.eventAuthority.publicKey,
6322
- program: this.programId,
6323
6489
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
6324
6490
  receivingMint: collateralCustodyConfig.mintKey
6325
6491
  })
@@ -6346,13 +6512,14 @@ var PerpetualsClient = (function () {
6346
6512
  for (var _i = 5; _i < arguments.length; _i++) {
6347
6513
  args_1[_i - 5] = arguments[_i];
6348
6514
  }
6349
- 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) {
6350
- 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_40;
6515
+ 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, isWhitelistedUser) {
6516
+ 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, whitelistPda, whitelistMeta, params, inx, closeWsolATAIns, err_40;
6351
6517
  if (useFeesPool === void 0) { useFeesPool = false; }
6352
6518
  if (createUserATA === void 0) { createUserATA = true; }
6353
6519
  if (unWrapSol === void 0) { unWrapSol = false; }
6354
6520
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6355
6521
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6522
+ if (isWhitelistedUser === void 0) { isWhitelistedUser = false; }
6356
6523
  return __generator(this, function (_g) {
6357
6524
  switch (_g.label) {
6358
6525
  case 0:
@@ -6513,6 +6680,12 @@ var PerpetualsClient = (function () {
6513
6680
  isWritable: false,
6514
6681
  });
6515
6682
  }
6683
+ whitelistPda = this.findProgramAddress("whitelist", [publicKey]).publicKey;
6684
+ whitelistMeta = {
6685
+ pubkey: whitelistPda,
6686
+ isSigner: false,
6687
+ isWritable: false,
6688
+ };
6516
6689
  params = {
6517
6690
  amountIn: amountIn,
6518
6691
  minAmountOut: minAmountOut,
@@ -6520,7 +6693,7 @@ var PerpetualsClient = (function () {
6520
6693
  };
6521
6694
  return [4, this.program.methods
6522
6695
  .swap(params)
6523
- .accounts({
6696
+ .accountsPartial({
6524
6697
  owner: publicKey,
6525
6698
  fundingAccount: userInputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
6526
6699
  receivingAccount: userOutputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userOutputTokenAccount,
@@ -6534,14 +6707,13 @@ var PerpetualsClient = (function () {
6534
6707
  dispensingCustodyOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
6535
6708
  dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
6536
6709
  eventAuthority: this.eventAuthority.publicKey,
6537
- program: this.programId,
6538
6710
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
6539
6711
  fundingMint: userInputCustodyConfig.mintKey,
6540
6712
  fundingTokenProgram: poolConfig.getTokenFromSymbol(userInputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
6541
6713
  receivingMint: userOutputCustodyConfig.mintKey,
6542
6714
  receivingTokenProgram: poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
6543
6715
  })
6544
- .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
6716
+ .remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), (isWhitelistedUser ? [whitelistMeta] : []), true))
6545
6717
  .instruction()];
6546
6718
  case 18:
6547
6719
  inx = _g.sent();
@@ -6602,15 +6774,13 @@ var PerpetualsClient = (function () {
6602
6774
  params = {};
6603
6775
  return [4, this.program.methods
6604
6776
  .swapFeeInternal(params)
6605
- .accounts({
6777
+ .accountsPartial({
6606
6778
  owner: publicKey,
6607
6779
  perpetuals: poolConfig.perpetuals,
6608
6780
  pool: poolConfig.poolAddress,
6609
6781
  rewardCustody: rewardCustody.custodyAccount,
6610
6782
  rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
6611
6783
  rewardCustodyTokenAccount: rewardCustody.tokenAccount,
6612
- eventAuthority: this.eventAuthority.publicKey,
6613
- program: this.programId,
6614
6784
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
6615
6785
  })
6616
6786
  .remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
@@ -6666,7 +6836,7 @@ var PerpetualsClient = (function () {
6666
6836
  }
6667
6837
  return [4, this.program.methods
6668
6838
  .setLpTokenPrice({})
6669
- .accounts({
6839
+ .accountsPartial({
6670
6840
  perpetuals: poolConfig.perpetuals,
6671
6841
  pool: poolConfig.poolAddress,
6672
6842
  lpTokenMint: poolConfig.stakedLpTokenMint,
@@ -6706,7 +6876,7 @@ var PerpetualsClient = (function () {
6706
6876
  }
6707
6877
  return [4, this.program.methods
6708
6878
  .init(config)
6709
- .accounts({
6879
+ .accountsPartial({
6710
6880
  upgradeAuthority: this.provider.wallet.publicKey,
6711
6881
  multisig: this.multisig.publicKey,
6712
6882
  transferAuthority: this.authority.publicKey,
@@ -6749,7 +6919,7 @@ var PerpetualsClient = (function () {
6749
6919
  .setAdminSigners({
6750
6920
  minSignatures: minSignatures,
6751
6921
  })
6752
- .accounts({
6922
+ .accountsPartial({
6753
6923
  admin: this.admin,
6754
6924
  multisig: this.multisig.publicKey,
6755
6925
  })
@@ -6786,7 +6956,7 @@ var PerpetualsClient = (function () {
6786
6956
  maxLpPriceUsd: maxLpPriceUsd,
6787
6957
  thresholdUsd: thresholdUsd
6788
6958
  })
6789
- .accounts({
6959
+ .accountsPartial({
6790
6960
  admin: this.provider.wallet.publicKey,
6791
6961
  multisig: this.multisig.publicKey,
6792
6962
  transferAuthority: this.authority.publicKey,
@@ -6813,7 +6983,7 @@ var PerpetualsClient = (function () {
6813
6983
  switch (_a.label) {
6814
6984
  case 0: return [4, this.program.methods
6815
6985
  .removePool({})
6816
- .accounts({
6986
+ .accountsPartial({
6817
6987
  admin: this.admin,
6818
6988
  multisig: this.multisig.publicKey,
6819
6989
  transferAuthority: this.authority.publicKey,
@@ -6832,7 +7002,7 @@ var PerpetualsClient = (function () {
6832
7002
  }
6833
7003
  });
6834
7004
  }); };
6835
- this.addCustody = function (poolName, tokenMint, isToken222, isStable, isVirtual, oracle, pricing, permissions, fees, borrowRate, ratios, depegAdjustment, rewardThreshold, minReserveUsd, limitPriceBufferBps) { return __awaiter(_this, void 0, void 0, function () {
7005
+ this.addCustody = function (poolName, tokenMint, isToken222, isStable, isVirtual, oracle, pricing, permissions, fees, borrowRate, ratios, depegAdjustment, rewardThreshold, minReserveUsd, limitPriceBufferBps, inversePrice) { return __awaiter(_this, void 0, void 0, function () {
6836
7006
  var trx_id, error_3;
6837
7007
  return __generator(this, function (_a) {
6838
7008
  switch (_a.label) {
@@ -6843,6 +7013,7 @@ var PerpetualsClient = (function () {
6843
7013
  isStable: isStable,
6844
7014
  depegAdjustment: depegAdjustment,
6845
7015
  isVirtual: isVirtual,
7016
+ inversePrice: inversePrice,
6846
7017
  token22: isToken222,
6847
7018
  oracle: oracle,
6848
7019
  pricing: pricing,
@@ -6854,7 +7025,7 @@ var PerpetualsClient = (function () {
6854
7025
  minReserveUsd: minReserveUsd,
6855
7026
  limitPriceBufferBps: limitPriceBufferBps
6856
7027
  })
6857
- .accounts({
7028
+ .accountsPartial({
6858
7029
  admin: this.admin,
6859
7030
  multisig: this.multisig.publicKey,
6860
7031
  transferAuthority: this.authority.publicKey,
@@ -6898,7 +7069,7 @@ var PerpetualsClient = (function () {
6898
7069
  borrowRate: borrowRate,
6899
7070
  ratios: ratios,
6900
7071
  })
6901
- .accounts({
7072
+ .accountsPartial({
6902
7073
  admin: this.admin,
6903
7074
  multisig: this.multisig.publicKey,
6904
7075
  transferAuthority: this.authority.publicKey,
@@ -6932,7 +7103,7 @@ var PerpetualsClient = (function () {
6932
7103
  userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, this.admin, true);
6933
7104
  return [4, this.program.methods
6934
7105
  .removeCustody({ ratios: ratios })
6935
- .accounts({
7106
+ .accountsPartial({
6936
7107
  admin: this.admin,
6937
7108
  receivingAccount: userReceivingTokenAccount,
6938
7109
  multisig: this.multisig.publicKey,
@@ -6975,7 +7146,7 @@ var PerpetualsClient = (function () {
6975
7146
  _a.trys.push([2, 4, , 5]);
6976
7147
  return [4, this.program.methods
6977
7148
  .withdrawFees({})
6978
- .accounts({
7149
+ .accountsPartial({
6979
7150
  admin: publicKey,
6980
7151
  multisig: this.multisig.publicKey,
6981
7152
  transferAuthority: this.authority.publicKey,
@@ -7003,12 +7174,12 @@ var PerpetualsClient = (function () {
7003
7174
  });
7004
7175
  }); };
7005
7176
  this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7006
- var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_45;
7177
+ var publicKey, rewardCustodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_45;
7007
7178
  return __generator(this, function (_a) {
7008
7179
  switch (_a.label) {
7009
7180
  case 0:
7010
7181
  publicKey = this.provider.wallet.publicKey;
7011
- custodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
7182
+ rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
7012
7183
  instructions = [];
7013
7184
  additionalSigners = [];
7014
7185
  _a.label = 1;
@@ -7016,20 +7187,19 @@ var PerpetualsClient = (function () {
7016
7187
  _a.trys.push([1, 3, , 4]);
7017
7188
  return [4, this.program.methods
7018
7189
  .moveProtocolFees()
7019
- .accounts({
7190
+ .accountsPartial({
7020
7191
  transferAuthority: this.authority.publicKey,
7021
7192
  perpetuals: this.perpetuals.publicKey,
7022
7193
  tokenVault: poolConfig.tokenVault,
7023
7194
  pool: poolConfig.poolAddress,
7024
- custody: custodyConfig.custodyAccount,
7025
- custodyTokenAccount: custodyConfig.tokenAccount,
7195
+ rewardCustody: rewardCustodyConfig.custodyAccount,
7196
+ rewardCustodyTokenAccount: rewardCustodyConfig.tokenAccount,
7026
7197
  revenueTokenAccount: poolConfig.revenueTokenAccount,
7027
7198
  protocolVault: poolConfig.protocolVault,
7028
7199
  protocolTokenAccount: poolConfig.protocolTokenAccount,
7029
7200
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
7030
- eventAuthority: this.eventAuthority.publicKey,
7031
7201
  program: this.program.programId,
7032
- tokenMint: custodyConfig.mintKey,
7202
+ tokenMint: rewardCustodyConfig.mintKey,
7033
7203
  })
7034
7204
  .instruction()];
7035
7205
  case 2:
@@ -7058,7 +7228,7 @@ var PerpetualsClient = (function () {
7058
7228
  .setProtocolFeeShare({
7059
7229
  feeShareBps: feeShareBps
7060
7230
  })
7061
- .accounts({
7231
+ .accountsPartial({
7062
7232
  admin: publicKey,
7063
7233
  multisig: this.multisig.publicKey,
7064
7234
  protocolVault: poolConfig.protocolVault,
@@ -7092,7 +7262,7 @@ var PerpetualsClient = (function () {
7092
7262
  .setPermissions({
7093
7263
  permissions: permissions,
7094
7264
  })
7095
- .accounts({
7265
+ .accountsPartial({
7096
7266
  admin: publicKey,
7097
7267
  multisig: this.multisig.publicKey,
7098
7268
  perpetuals: this.perpetuals.publicKey
@@ -7151,7 +7321,7 @@ var PerpetualsClient = (function () {
7151
7321
  _g.trys.push([1, 4, , 5]);
7152
7322
  _e = (_d = this.program.methods
7153
7323
  .reimburse({ amountIn: amountIn }))
7154
- .accounts;
7324
+ .accountsPartial;
7155
7325
  _f = {
7156
7326
  admin: this.provider.wallet.publicKey,
7157
7327
  multisig: poolConfig.multisig
@@ -7205,7 +7375,7 @@ var PerpetualsClient = (function () {
7205
7375
  ema: ema,
7206
7376
  publishTime: publishTime,
7207
7377
  })
7208
- .accounts({
7378
+ .accountsPartial({
7209
7379
  authority: poolConfig.backupOracle,
7210
7380
  perpetuals: poolConfig.perpetuals,
7211
7381
  pool: poolConfig.poolAddress,
@@ -7267,7 +7437,7 @@ var PerpetualsClient = (function () {
7267
7437
  useCurrentTime: useCurrentTime,
7268
7438
  prices: tokenInternalPrices
7269
7439
  })
7270
- .accounts({
7440
+ .accountsPartial({
7271
7441
  authority: POOL_CONFIGS[0].backupOracle,
7272
7442
  })
7273
7443
  .remainingAccounts(__spreadArray([], accountMetas, true))
@@ -7318,7 +7488,7 @@ var PerpetualsClient = (function () {
7318
7488
  .setInternalEmaPrice({
7319
7489
  prices: tokenInternalEmaPrices
7320
7490
  })
7321
- .accounts({
7491
+ .accountsPartial({
7322
7492
  authority: POOL_CONFIGS[0].backupOracle,
7323
7493
  })
7324
7494
  .remainingAccounts(__spreadArray([], accountMetas, true))
@@ -7338,8 +7508,43 @@ var PerpetualsClient = (function () {
7338
7508
  }
7339
7509
  });
7340
7510
  }); };
7511
+ this.setPositionPriceImpact = function (positionPubkey, priceImpactUsd, penaltyAuthority) { return __awaiter(_this, void 0, void 0, function () {
7512
+ var instructions, additionalSigners, setPositionPriceImpactIx, err_52;
7513
+ return __generator(this, function (_a) {
7514
+ switch (_a.label) {
7515
+ case 0:
7516
+ instructions = [];
7517
+ additionalSigners = [];
7518
+ _a.label = 1;
7519
+ case 1:
7520
+ _a.trys.push([1, 3, , 4]);
7521
+ return [4, this.program.methods
7522
+ .setPositionPriceImpact({
7523
+ priceImpactUsd: priceImpactUsd,
7524
+ })
7525
+ .accountsPartial({
7526
+ authority: penaltyAuthority,
7527
+ position: positionPubkey,
7528
+ program: this.program.programId,
7529
+ })
7530
+ .instruction()];
7531
+ case 2:
7532
+ setPositionPriceImpactIx = _a.sent();
7533
+ instructions.push(setPositionPriceImpactIx);
7534
+ return [3, 4];
7535
+ case 3:
7536
+ err_52 = _a.sent();
7537
+ console.log("perpClient setPositionPriceImpact error:: ", err_52);
7538
+ throw err_52;
7539
+ case 4: return [2, {
7540
+ instructions: __spreadArray([], instructions, true),
7541
+ additionalSigners: additionalSigners
7542
+ }];
7543
+ }
7544
+ });
7545
+ }); };
7341
7546
  this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7342
- var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_52;
7547
+ var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_53;
7343
7548
  return __generator(this, function (_a) {
7344
7549
  switch (_a.label) {
7345
7550
  case 0:
@@ -7358,7 +7563,7 @@ var PerpetualsClient = (function () {
7358
7563
  lpTokenSymbol: lpTokenSymbol,
7359
7564
  lpTokenUri: lpTokenUri,
7360
7565
  })
7361
- .accounts({
7566
+ .accountsPartial({
7362
7567
  admin: publicKey,
7363
7568
  multisig: this.multisig.publicKey,
7364
7569
  transferAuthority: poolConfig.transferAuthority,
@@ -7377,8 +7582,8 @@ var PerpetualsClient = (function () {
7377
7582
  instructions.push(renameFlp);
7378
7583
  return [3, 4];
7379
7584
  case 3:
7380
- err_52 = _a.sent();
7381
- console.log("perpClient renameFlp error:: ", err_52);
7585
+ err_53 = _a.sent();
7586
+ console.log("perpClient renameFlp error:: ", err_53);
7382
7587
  return [3, 4];
7383
7588
  case 4: return [2, {
7384
7589
  instructions: __spreadArray([], instructions, true),
@@ -7388,7 +7593,7 @@ var PerpetualsClient = (function () {
7388
7593
  });
7389
7594
  }); };
7390
7595
  this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7391
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_53;
7596
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_54;
7392
7597
  return __generator(this, function (_a) {
7393
7598
  switch (_a.label) {
7394
7599
  case 0:
@@ -7407,7 +7612,7 @@ var PerpetualsClient = (function () {
7407
7612
  .initStaking({
7408
7613
  stakingFeeShareBps: stakingFeeShareBps
7409
7614
  })
7410
- .accounts({
7615
+ .accountsPartial({
7411
7616
  admin: publicKey,
7412
7617
  multisig: this.multisig.publicKey,
7413
7618
  transferAuthority: poolConfig.transferAuthority,
@@ -7426,9 +7631,9 @@ var PerpetualsClient = (function () {
7426
7631
  instructions.push(initStakeInstruction);
7427
7632
  return [3, 4];
7428
7633
  case 3:
7429
- err_53 = _a.sent();
7430
- console.log("perpClient InitStaking error:: ", err_53);
7431
- throw err_53;
7634
+ err_54 = _a.sent();
7635
+ console.log("perpClient InitStaking error:: ", err_54);
7636
+ throw err_54;
7432
7637
  case 4: return [2, {
7433
7638
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7434
7639
  additionalSigners: additionalSigners
@@ -7437,7 +7642,7 @@ var PerpetualsClient = (function () {
7437
7642
  });
7438
7643
  }); };
7439
7644
  this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7440
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_54;
7645
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_55;
7441
7646
  return __generator(this, function (_a) {
7442
7647
  switch (_a.label) {
7443
7648
  case 0:
@@ -7460,7 +7665,7 @@ var PerpetualsClient = (function () {
7460
7665
  metadataSymbol: metadataSymbol,
7461
7666
  metadataUri: metadataUri
7462
7667
  })
7463
- .accounts({
7668
+ .accountsPartial({
7464
7669
  admin: publicKey,
7465
7670
  multisig: this.multisig.publicKey,
7466
7671
  transferAuthority: poolConfig.transferAuthority,
@@ -7481,10 +7686,10 @@ var PerpetualsClient = (function () {
7481
7686
  instructions.push(initCompoundingInstruction);
7482
7687
  return [3, 4];
7483
7688
  case 3:
7484
- err_54 = _a.sent();
7485
- console.log("perpClient initCompounding error:: ", err_54);
7486
- throw err_54;
7487
- case 4: return [2, {
7689
+ err_55 = _a.sent();
7690
+ console.log("perpClient initCompounding error:: ", err_55);
7691
+ throw err_55;
7692
+ case 4: return [2, {
7488
7693
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7489
7694
  additionalSigners: additionalSigners
7490
7695
  }];
@@ -7492,7 +7697,7 @@ var PerpetualsClient = (function () {
7492
7697
  });
7493
7698
  }); };
7494
7699
  this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7495
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_55;
7700
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_56;
7496
7701
  return __generator(this, function (_a) {
7497
7702
  switch (_a.label) {
7498
7703
  case 0:
@@ -7514,7 +7719,7 @@ var PerpetualsClient = (function () {
7514
7719
  withdrawInstantFee: withdrawInstantFee,
7515
7720
  stakeLevel: stakeLevel,
7516
7721
  })
7517
- .accounts({
7722
+ .accountsPartial({
7518
7723
  admin: publicKey,
7519
7724
  multisig: this.multisig.publicKey,
7520
7725
  perpetuals: this.perpetuals.publicKey,
@@ -7533,9 +7738,9 @@ var PerpetualsClient = (function () {
7533
7738
  instructions.push(initTokenVaultInstruction);
7534
7739
  return [3, 4];
7535
7740
  case 3:
7536
- err_55 = _a.sent();
7537
- console.log("perpClient InitTokenVaultInstruction error:: ", err_55);
7538
- throw err_55;
7741
+ err_56 = _a.sent();
7742
+ console.log("perpClient InitTokenVaultInstruction error:: ", err_56);
7743
+ throw err_56;
7539
7744
  case 4: return [2, {
7540
7745
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7541
7746
  additionalSigners: additionalSigners
@@ -7544,7 +7749,7 @@ var PerpetualsClient = (function () {
7544
7749
  });
7545
7750
  }); };
7546
7751
  this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7547
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_56;
7752
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_57;
7548
7753
  return __generator(this, function (_a) {
7549
7754
  switch (_a.label) {
7550
7755
  case 0:
@@ -7563,7 +7768,7 @@ var PerpetualsClient = (function () {
7563
7768
  withdrawInstantFee: withdrawInstantFee,
7564
7769
  stakeLevel: stakeLevel,
7565
7770
  })
7566
- .accounts({
7771
+ .accountsPartial({
7567
7772
  admin: publicKey,
7568
7773
  multisig: this.multisig.publicKey,
7569
7774
  tokenVault: poolConfig.tokenVault,
@@ -7575,9 +7780,9 @@ var PerpetualsClient = (function () {
7575
7780
  instructions.push(setTokenVaultConfigInstruction);
7576
7781
  return [3, 4];
7577
7782
  case 3:
7578
- err_56 = _a.sent();
7579
- console.log("perpClient setTokenVaultConfigInstruction error:: ", err_56);
7580
- throw err_56;
7783
+ err_57 = _a.sent();
7784
+ console.log("perpClient setTokenVaultConfigInstruction error:: ", err_57);
7785
+ throw err_57;
7581
7786
  case 4: return [2, {
7582
7787
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7583
7788
  additionalSigners: additionalSigners
@@ -7586,7 +7791,7 @@ var PerpetualsClient = (function () {
7586
7791
  });
7587
7792
  }); };
7588
7793
  this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7589
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_57;
7794
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_58;
7590
7795
  return __generator(this, function (_a) {
7591
7796
  switch (_a.label) {
7592
7797
  case 0:
@@ -7608,7 +7813,7 @@ var PerpetualsClient = (function () {
7608
7813
  }
7609
7814
  return [4, this.program.methods
7610
7815
  .withdrawInstantFees({})
7611
- .accounts({
7816
+ .accountsPartial({
7612
7817
  admin: publicKey,
7613
7818
  multisig: this.multisig.publicKey,
7614
7819
  perpetuals: this.perpetuals.publicKey,
@@ -7625,9 +7830,9 @@ var PerpetualsClient = (function () {
7625
7830
  instructions.push(withdrawInstantFeeInstruction);
7626
7831
  return [3, 6];
7627
7832
  case 5:
7628
- err_57 = _a.sent();
7629
- console.log("perpClient withdrawInstantFeeInstruction error:: ", err_57);
7630
- throw err_57;
7833
+ err_58 = _a.sent();
7834
+ console.log("perpClient withdrawInstantFeeInstruction error:: ", err_58);
7835
+ throw err_58;
7631
7836
  case 6: return [2, {
7632
7837
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7633
7838
  additionalSigners: additionalSigners
@@ -7636,7 +7841,7 @@ var PerpetualsClient = (function () {
7636
7841
  });
7637
7842
  }); };
7638
7843
  this.withdrawUnclaimedTokens = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7639
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawUnclaimedTokensInstruction, err_58;
7844
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawUnclaimedTokensInstruction, err_59;
7640
7845
  return __generator(this, function (_a) {
7641
7846
  switch (_a.label) {
7642
7847
  case 0:
@@ -7658,7 +7863,7 @@ var PerpetualsClient = (function () {
7658
7863
  }
7659
7864
  return [4, this.program.methods
7660
7865
  .withdrawUnclaimedTokens({})
7661
- .accounts({
7866
+ .accountsPartial({
7662
7867
  admin: publicKey,
7663
7868
  multisig: this.multisig.publicKey,
7664
7869
  perpetuals: this.perpetuals.publicKey,
@@ -7675,9 +7880,9 @@ var PerpetualsClient = (function () {
7675
7880
  instructions.push(withdrawUnclaimedTokensInstruction);
7676
7881
  return [3, 6];
7677
7882
  case 5:
7678
- err_58 = _a.sent();
7679
- console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_58);
7680
- throw err_58;
7883
+ err_59 = _a.sent();
7884
+ console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_59);
7885
+ throw err_59;
7681
7886
  case 6: return [2, {
7682
7887
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7683
7888
  additionalSigners: additionalSigners
@@ -7686,7 +7891,7 @@ var PerpetualsClient = (function () {
7686
7891
  });
7687
7892
  }); };
7688
7893
  this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7689
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_59;
7894
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_60;
7690
7895
  return __generator(this, function (_a) {
7691
7896
  switch (_a.label) {
7692
7897
  case 0:
@@ -7703,7 +7908,7 @@ var PerpetualsClient = (function () {
7703
7908
  .initRevenueTokenAccount({
7704
7909
  feeShareBps: feeShareBps
7705
7910
  })
7706
- .accounts({
7911
+ .accountsPartial({
7707
7912
  admin: publicKey,
7708
7913
  multisig: this.multisig.publicKey,
7709
7914
  perpetuals: this.perpetuals.publicKey,
@@ -7723,9 +7928,9 @@ var PerpetualsClient = (function () {
7723
7928
  instructions.push(initRevenueTokenAccountInstruction);
7724
7929
  return [3, 4];
7725
7930
  case 3:
7726
- err_59 = _a.sent();
7727
- console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_59);
7728
- throw err_59;
7931
+ err_60 = _a.sent();
7932
+ console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_60);
7933
+ throw err_60;
7729
7934
  case 4: return [2, {
7730
7935
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7731
7936
  additionalSigners: additionalSigners
@@ -7734,7 +7939,7 @@ var PerpetualsClient = (function () {
7734
7939
  });
7735
7940
  }); };
7736
7941
  this.initRebateVault = function (allowRebatePayout, rebateSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7737
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateCustodyMint, initRebateVaultInstruction, err_60;
7942
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateCustodyMint, initRebateVaultInstruction, err_61;
7738
7943
  return __generator(this, function (_a) {
7739
7944
  switch (_a.label) {
7740
7945
  case 0:
@@ -7751,7 +7956,7 @@ var PerpetualsClient = (function () {
7751
7956
  .initRebateVault({
7752
7957
  allowRebatePayout: allowRebatePayout
7753
7958
  })
7754
- .accounts({
7959
+ .accountsPartial({
7755
7960
  admin: publicKey,
7756
7961
  multisig: this.multisig.publicKey,
7757
7962
  transferAuthority: poolConfig.transferAuthority,
@@ -7769,9 +7974,9 @@ var PerpetualsClient = (function () {
7769
7974
  instructions.push(initRebateVaultInstruction);
7770
7975
  return [3, 4];
7771
7976
  case 3:
7772
- err_60 = _a.sent();
7773
- console.log("perpClient initRebateVaultInstruction error:: ", err_60);
7774
- throw err_60;
7977
+ err_61 = _a.sent();
7978
+ console.log("perpClient initRebateVaultInstruction error:: ", err_61);
7979
+ throw err_61;
7775
7980
  case 4: return [2, {
7776
7981
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7777
7982
  additionalSigners: additionalSigners
@@ -7780,7 +7985,7 @@ var PerpetualsClient = (function () {
7780
7985
  });
7781
7986
  }); };
7782
7987
  this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7783
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_61;
7988
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_62;
7784
7989
  return __generator(this, function (_a) {
7785
7990
  switch (_a.label) {
7786
7991
  case 0:
@@ -7800,7 +8005,7 @@ var PerpetualsClient = (function () {
7800
8005
  amount: amount,
7801
8006
  epochCount: epochCount,
7802
8007
  })
7803
- .accounts({
8008
+ .accountsPartial({
7804
8009
  admin: publicKey,
7805
8010
  multisig: this.multisig.publicKey,
7806
8011
  perpetuals: this.perpetuals.publicKey,
@@ -7809,8 +8014,6 @@ var PerpetualsClient = (function () {
7809
8014
  tokenVault: poolConfig.tokenVault,
7810
8015
  tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
7811
8016
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
7812
- eventAuthority: this.eventAuthority.publicKey,
7813
- program: this.programId,
7814
8017
  tokenMint: poolConfig.tokenMint,
7815
8018
  })
7816
8019
  .instruction()];
@@ -7819,9 +8022,9 @@ var PerpetualsClient = (function () {
7819
8022
  instructions.push(distributeTokenRewardInstruction);
7820
8023
  return [3, 4];
7821
8024
  case 3:
7822
- err_61 = _a.sent();
7823
- console.log("perpClient distributeTokenRewardInstruction error:: ", err_61);
7824
- throw err_61;
8025
+ err_62 = _a.sent();
8026
+ console.log("perpClient distributeTokenRewardInstruction error:: ", err_62);
8027
+ throw err_62;
7825
8028
  case 4: return [2, {
7826
8029
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7827
8030
  additionalSigners: additionalSigners
@@ -7829,8 +8032,8 @@ var PerpetualsClient = (function () {
7829
8032
  }
7830
8033
  });
7831
8034
  }); };
7832
- this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
7833
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_62;
8035
+ this.setTokenStakeLevel = function (owner, stakeLevel, isInitialized) { return __awaiter(_this, void 0, void 0, function () {
8036
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_63;
7834
8037
  return __generator(this, function (_a) {
7835
8038
  switch (_a.label) {
7836
8039
  case 0:
@@ -7846,8 +8049,9 @@ var PerpetualsClient = (function () {
7846
8049
  return [4, this.program.methods
7847
8050
  .setTokenStakeLevel({
7848
8051
  level: stakeLevel,
8052
+ init: isInitialized,
7849
8053
  })
7850
- .accounts({
8054
+ .accountsPartial({
7851
8055
  admin: publicKey,
7852
8056
  multisig: this.multisig.publicKey,
7853
8057
  tokenStakeAccount: tokenStakeAccount,
@@ -7858,9 +8062,9 @@ var PerpetualsClient = (function () {
7858
8062
  instructions.push(setTokenStakeLevelInstruction);
7859
8063
  return [3, 4];
7860
8064
  case 3:
7861
- err_62 = _a.sent();
7862
- console.log("perpClient setTokenStakeLevelInstruction error:: ", err_62);
7863
- throw err_62;
8065
+ err_63 = _a.sent();
8066
+ console.log("perpClient setTokenStakeLevelInstruction error:: ", err_63);
8067
+ throw err_63;
7864
8068
  case 4: return [2, {
7865
8069
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7866
8070
  additionalSigners: additionalSigners
@@ -7869,7 +8073,7 @@ var PerpetualsClient = (function () {
7869
8073
  });
7870
8074
  }); };
7871
8075
  this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7872
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_63;
8076
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_64;
7873
8077
  return __generator(this, function (_a) {
7874
8078
  switch (_a.label) {
7875
8079
  case 0:
@@ -7887,12 +8091,11 @@ var PerpetualsClient = (function () {
7887
8091
  amount: amount,
7888
8092
  epochCount: epochCount,
7889
8093
  })
7890
- .accounts({
8094
+ .accountsPartial({
7891
8095
  admin: publicKey,
7892
8096
  multisig: this.multisig.publicKey,
7893
8097
  tokenVault: poolConfig.tokenVault,
7894
8098
  tokenStakeAccount: tokenStakeAccount,
7895
- eventAuthority: this.eventAuthority.publicKey,
7896
8099
  program: this.programId
7897
8100
  })
7898
8101
  .instruction()];
@@ -7901,9 +8104,9 @@ var PerpetualsClient = (function () {
7901
8104
  instructions.push(setTokenRewardInstruction);
7902
8105
  return [3, 4];
7903
8106
  case 3:
7904
- err_63 = _a.sent();
7905
- console.log("perpClient setTokenRewardInstruction error:: ", err_63);
7906
- throw err_63;
8107
+ err_64 = _a.sent();
8108
+ console.log("perpClient setTokenRewardInstruction error:: ", err_64);
8109
+ throw err_64;
7907
8110
  case 4: return [2, {
7908
8111
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7909
8112
  additionalSigners: additionalSigners
@@ -7912,7 +8115,7 @@ var PerpetualsClient = (function () {
7912
8115
  });
7913
8116
  }); };
7914
8117
  this.resizeInternalOracle = function (extOracle, tokenMint, intOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
7915
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_64;
8118
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_65;
7916
8119
  return __generator(this, function (_a) {
7917
8120
  switch (_a.label) {
7918
8121
  case 0:
@@ -7928,7 +8131,7 @@ var PerpetualsClient = (function () {
7928
8131
  .resizeInternalOracle({
7929
8132
  extOracle: extOracle
7930
8133
  })
7931
- .accounts({
8134
+ .accountsPartial({
7932
8135
  admin: publicKey,
7933
8136
  multisig: this.multisig.publicKey,
7934
8137
  custodyTokenMint: tokenMint,
@@ -7941,9 +8144,457 @@ var PerpetualsClient = (function () {
7941
8144
  instructions.push(resizeInternalOracleInstruction);
7942
8145
  return [3, 4];
7943
8146
  case 3:
7944
- err_64 = _a.sent();
7945
- console.log("perpClient resizeInternalOracleInstruction error:: ", err_64);
7946
- throw err_64;
8147
+ err_65 = _a.sent();
8148
+ console.log("perpClient resizeInternalOracleInstruction error:: ", err_65);
8149
+ throw err_65;
8150
+ case 4: return [2, {
8151
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8152
+ additionalSigners: additionalSigners
8153
+ }];
8154
+ }
8155
+ });
8156
+ }); };
8157
+ this.createWhitelist = function (isSwapFeeExempt, isDepositFeeExempt, isWithdrawalFeeExempt, poolAddress, owner) { return __awaiter(_this, void 0, void 0, function () {
8158
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, whitelist, createWhitelistInstruction, err_66;
8159
+ return __generator(this, function (_a) {
8160
+ switch (_a.label) {
8161
+ case 0:
8162
+ publicKey = this.provider.wallet.publicKey;
8163
+ preInstructions = [];
8164
+ instructions = [];
8165
+ postInstructions = [];
8166
+ additionalSigners = [];
8167
+ _a.label = 1;
8168
+ case 1:
8169
+ _a.trys.push([1, 3, , 4]);
8170
+ whitelist = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("whitelist"), owner.toBuffer()], this.programId)[0];
8171
+ return [4, this.program.methods
8172
+ .createWhitelist({
8173
+ isSwapFeeExempt: isSwapFeeExempt,
8174
+ isDepositFeeExempt: isDepositFeeExempt,
8175
+ isWithdrawalFeeExempt: isWithdrawalFeeExempt,
8176
+ poolAddress: poolAddress,
8177
+ })
8178
+ .accountsPartial({
8179
+ admin: publicKey,
8180
+ multisig: this.multisig.publicKey,
8181
+ owner: owner,
8182
+ whitelist: whitelist,
8183
+ systemProgram: web3_js_1.SystemProgram.programId,
8184
+ })
8185
+ .instruction()];
8186
+ case 2:
8187
+ createWhitelistInstruction = _a.sent();
8188
+ instructions.push(createWhitelistInstruction);
8189
+ return [3, 4];
8190
+ case 3:
8191
+ err_66 = _a.sent();
8192
+ console.log("perpClient createWhitelistInstruction error:: ", err_66);
8193
+ throw err_66;
8194
+ case 4: return [2, {
8195
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8196
+ additionalSigners: additionalSigners
8197
+ }];
8198
+ }
8199
+ });
8200
+ }); };
8201
+ this.setWhitelistConfig = function (isSwapFeeExempt, isDepositFeeExempt, isWithdrawalFeeExempt, poolAddress, owner) { return __awaiter(_this, void 0, void 0, function () {
8202
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, whitelist, setWhitelistConfigInstruction, err_67;
8203
+ return __generator(this, function (_a) {
8204
+ switch (_a.label) {
8205
+ case 0:
8206
+ publicKey = this.provider.wallet.publicKey;
8207
+ preInstructions = [];
8208
+ instructions = [];
8209
+ postInstructions = [];
8210
+ additionalSigners = [];
8211
+ _a.label = 1;
8212
+ case 1:
8213
+ _a.trys.push([1, 3, , 4]);
8214
+ whitelist = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("whitelist"), owner.toBuffer()], this.programId)[0];
8215
+ return [4, this.program.methods
8216
+ .setWhitelistConfig({
8217
+ isSwapFeeExempt: isSwapFeeExempt,
8218
+ isDepositFeeExempt: isDepositFeeExempt,
8219
+ isWithdrawalFeeExempt: isWithdrawalFeeExempt,
8220
+ poolAddress: poolAddress
8221
+ })
8222
+ .accountsPartial({
8223
+ admin: publicKey,
8224
+ multisig: this.multisig.publicKey,
8225
+ owner: owner,
8226
+ whitelist: whitelist,
8227
+ systemProgram: web3_js_1.SystemProgram.programId,
8228
+ })
8229
+ .instruction()];
8230
+ case 2:
8231
+ setWhitelistConfigInstruction = _a.sent();
8232
+ instructions.push(setWhitelistConfigInstruction);
8233
+ return [3, 4];
8234
+ case 3:
8235
+ err_67 = _a.sent();
8236
+ console.log("perpClient setWhitelistConfigInstruction error:: ", err_67);
8237
+ throw err_67;
8238
+ case 4: return [2, {
8239
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8240
+ additionalSigners: additionalSigners
8241
+ }];
8242
+ }
8243
+ });
8244
+ }); };
8245
+ this.setPerpetualsConfig = function (allowUngatedTrading, voltageMultiplier, tradingDiscount, referralRebate, defaultRebate, tradeLimit, triggerOrderLimit, rebateLimitUsd) { return __awaiter(_this, void 0, void 0, function () {
8246
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPerpetualsConfigInstruction, err_68;
8247
+ return __generator(this, function (_a) {
8248
+ switch (_a.label) {
8249
+ case 0:
8250
+ publicKey = this.provider.wallet.publicKey;
8251
+ preInstructions = [];
8252
+ instructions = [];
8253
+ postInstructions = [];
8254
+ additionalSigners = [];
8255
+ _a.label = 1;
8256
+ case 1:
8257
+ _a.trys.push([1, 3, , 4]);
8258
+ return [4, this.program.methods
8259
+ .setPerpetualsConfig({
8260
+ allowUngatedTrading: allowUngatedTrading,
8261
+ tradingDiscount: tradingDiscount,
8262
+ referralRebate: referralRebate,
8263
+ defaultRebate: defaultRebate,
8264
+ voltageMultiplier: voltageMultiplier,
8265
+ tradeLimit: tradeLimit,
8266
+ triggerOrderLimit: triggerOrderLimit,
8267
+ rebateLimitUsd: rebateLimitUsd,
8268
+ })
8269
+ .accountsPartial({
8270
+ admin: publicKey,
8271
+ multisig: this.multisig.publicKey,
8272
+ perpetuals: this.perpetuals.publicKey,
8273
+ })
8274
+ .instruction()];
8275
+ case 2:
8276
+ setPerpetualsConfigInstruction = _a.sent();
8277
+ instructions.push(setPerpetualsConfigInstruction);
8278
+ return [3, 4];
8279
+ case 3:
8280
+ err_68 = _a.sent();
8281
+ console.log("perpClient setPerpetualsConfigInstruction error:: ", err_68);
8282
+ throw err_68;
8283
+ case 4: return [2, {
8284
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8285
+ additionalSigners: additionalSigners
8286
+ }];
8287
+ }
8288
+ });
8289
+ }); };
8290
+ this.setPoolConfig = function (name, permissions, maxAumUsd, oracleAuthority, stakingFeeShareBps, vpVolumeFactor, stakingFeeBoostBps, minLpPriceUsd, maxLpPriceUsd, thresholdUsd) { return __awaiter(_this, void 0, void 0, function () {
8291
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPoolConfigInstruction, err_69;
8292
+ return __generator(this, function (_a) {
8293
+ switch (_a.label) {
8294
+ case 0:
8295
+ publicKey = this.provider.wallet.publicKey;
8296
+ preInstructions = [];
8297
+ instructions = [];
8298
+ postInstructions = [];
8299
+ additionalSigners = [];
8300
+ _a.label = 1;
8301
+ case 1:
8302
+ _a.trys.push([1, 3, , 4]);
8303
+ console.log(vpVolumeFactor);
8304
+ return [4, this.program.methods
8305
+ .setPoolConfig({ permissions: permissions, oracleAuthority: oracleAuthority, maxAumUsd: maxAumUsd, stakingFeeShareBps: stakingFeeShareBps, vpVolumeFactor: vpVolumeFactor, stakingFeeBoostBps: stakingFeeBoostBps, minLpPriceUsd: minLpPriceUsd, maxLpPriceUsd: maxLpPriceUsd, thresholdUsd: thresholdUsd
8306
+ })
8307
+ .accountsPartial({
8308
+ admin: publicKey,
8309
+ multisig: this.multisig.publicKey,
8310
+ pool: this.getPoolKey(name),
8311
+ systemProgram: web3_js_1.SystemProgram.programId,
8312
+ })
8313
+ .instruction()];
8314
+ case 2:
8315
+ setPoolConfigInstruction = _a.sent();
8316
+ instructions.push(setPoolConfigInstruction);
8317
+ return [3, 4];
8318
+ case 3:
8319
+ err_69 = _a.sent();
8320
+ console.log("perpClient setPoolConfigInstruction error:: ", err_69);
8321
+ throw err_69;
8322
+ case 4: return [2, {
8323
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8324
+ additionalSigners: additionalSigners
8325
+ }];
8326
+ }
8327
+ });
8328
+ }); };
8329
+ this.addCustodyToken22 = function (poolName, tokenMint, tokenAccountSpace, token22) { return __awaiter(_this, void 0, void 0, function () {
8330
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, addCustodyToken22Instruction, err_70;
8331
+ return __generator(this, function (_a) {
8332
+ switch (_a.label) {
8333
+ case 0:
8334
+ publicKey = this.provider.wallet.publicKey;
8335
+ preInstructions = [];
8336
+ instructions = [];
8337
+ postInstructions = [];
8338
+ additionalSigners = [];
8339
+ _a.label = 1;
8340
+ case 1:
8341
+ _a.trys.push([1, 3, , 4]);
8342
+ return [4, this.program.methods
8343
+ .addCustodyToken22Account({
8344
+ tokenAccountSpace: tokenAccountSpace
8345
+ })
8346
+ .accountsPartial({
8347
+ admin: publicKey,
8348
+ multisig: this.multisig.publicKey,
8349
+ transferAuthority: this.authority.publicKey,
8350
+ perpetuals: this.perpetuals.publicKey,
8351
+ pool: this.getPoolKey(poolName),
8352
+ custodyTokenAccount: this.getCustodyTokenAccountKey(poolName, tokenMint),
8353
+ custodyTokenMint: tokenMint,
8354
+ systemProgram: web3_js_1.SystemProgram.programId,
8355
+ tokenProgram: token22 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
8356
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
8357
+ })
8358
+ .instruction()];
8359
+ case 2:
8360
+ addCustodyToken22Instruction = _a.sent();
8361
+ instructions.push(addCustodyToken22Instruction);
8362
+ return [3, 4];
8363
+ case 3:
8364
+ err_70 = _a.sent();
8365
+ console.log("perpClient addCustodyToken22Instruction error:: ", err_70);
8366
+ throw err_70;
8367
+ case 4: return [2, {
8368
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8369
+ additionalSigners: additionalSigners
8370
+ }];
8371
+ }
8372
+ });
8373
+ }); };
8374
+ this.addMarket = function (poolName, targetCustody, collateralCustody, side, correlation, maxPayoffBps, permissions) { return __awaiter(_this, void 0, void 0, function () {
8375
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, market, addMarketInstruction, err_71;
8376
+ return __generator(this, function (_a) {
8377
+ switch (_a.label) {
8378
+ case 0:
8379
+ publicKey = this.provider.wallet.publicKey;
8380
+ preInstructions = [];
8381
+ instructions = [];
8382
+ postInstructions = [];
8383
+ additionalSigners = [];
8384
+ _a.label = 1;
8385
+ case 1:
8386
+ _a.trys.push([1, 3, , 4]);
8387
+ market = web3_js_1.PublicKey.findProgramAddressSync([
8388
+ Buffer.from("market"),
8389
+ targetCustody.toBuffer(),
8390
+ collateralCustody.toBuffer(),
8391
+ (0, types_1.isVariant)(side, 'long') ? Buffer.from([1]) : Buffer.from([2]),
8392
+ ], this.program.programId)[0];
8393
+ return [4, this.program.methods
8394
+ .addMarket({
8395
+ side: side === "long" ? { long: {} } : { short: {} },
8396
+ correlation: correlation,
8397
+ maxPayoffBps: maxPayoffBps,
8398
+ permissions: permissions
8399
+ })
8400
+ .accountsPartial({
8401
+ admin: publicKey,
8402
+ multisig: this.multisig.publicKey,
8403
+ transferAuthority: this.authority.publicKey,
8404
+ perpetuals: this.perpetuals.publicKey,
8405
+ pool: this.getPoolKey(poolName),
8406
+ market: market,
8407
+ targetCustody: targetCustody,
8408
+ collateralCustody: collateralCustody,
8409
+ systemProgram: web3_js_1.SystemProgram.programId,
8410
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY
8411
+ })
8412
+ .instruction()];
8413
+ case 2:
8414
+ addMarketInstruction = _a.sent();
8415
+ instructions.push(addMarketInstruction);
8416
+ return [3, 4];
8417
+ case 3:
8418
+ err_71 = _a.sent();
8419
+ console.log("perpClient addMarketInstruction error:: ", err_71);
8420
+ throw err_71;
8421
+ case 4: return [2, {
8422
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8423
+ additionalSigners: additionalSigners
8424
+ }];
8425
+ }
8426
+ });
8427
+ }); };
8428
+ this.setCustody = function (poolName, tokenMint, depegAdjustment, inversePrice, oracle, pricingConfig, permissions, fees, borrowRate, ratios, rewardThreshold, minReserveUsd, limitPriceBufferBps, token22) { return __awaiter(_this, void 0, void 0, function () {
8429
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setCustodyConfigInstruction, err_72;
8430
+ return __generator(this, function (_a) {
8431
+ switch (_a.label) {
8432
+ case 0:
8433
+ publicKey = this.provider.wallet.publicKey;
8434
+ preInstructions = [];
8435
+ instructions = [];
8436
+ postInstructions = [];
8437
+ additionalSigners = [];
8438
+ _a.label = 1;
8439
+ case 1:
8440
+ _a.trys.push([1, 3, , 4]);
8441
+ return [4, this.program.methods
8442
+ .setCustodyConfig({
8443
+ depegAdjustment: depegAdjustment,
8444
+ inversePrice: inversePrice,
8445
+ oracle: oracle,
8446
+ pricing: pricingConfig,
8447
+ permissions: permissions,
8448
+ fees: fees,
8449
+ borrowRate: borrowRate,
8450
+ ratios: ratios,
8451
+ rewardThreshold: rewardThreshold,
8452
+ minReserveUsd: minReserveUsd,
8453
+ limitPriceBufferBps: limitPriceBufferBps,
8454
+ token22: token22
8455
+ })
8456
+ .accountsPartial({
8457
+ admin: this.admin,
8458
+ multisig: this.multisig.publicKey,
8459
+ pool: this.getPoolKey(poolName),
8460
+ custody: this.getCustodyKey(poolName, tokenMint),
8461
+ })
8462
+ .instruction()];
8463
+ case 2:
8464
+ setCustodyConfigInstruction = _a.sent();
8465
+ instructions.push(setCustodyConfigInstruction);
8466
+ return [3, 4];
8467
+ case 3:
8468
+ err_72 = _a.sent();
8469
+ console.log("perpClient setCustodyConfigInstruction error:: ", err_72);
8470
+ throw err_72;
8471
+ case 4: return [2, {
8472
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8473
+ additionalSigners: additionalSigners
8474
+ }];
8475
+ }
8476
+ });
8477
+ }); };
8478
+ this.addInternalOracle = function (exponent, tokenMint, intOracleAccount, extOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
8479
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, addInternalOracleInstruction, err_73;
8480
+ return __generator(this, function (_a) {
8481
+ switch (_a.label) {
8482
+ case 0:
8483
+ publicKey = this.provider.wallet.publicKey;
8484
+ preInstructions = [];
8485
+ instructions = [];
8486
+ postInstructions = [];
8487
+ additionalSigners = [];
8488
+ _a.label = 1;
8489
+ case 1:
8490
+ _a.trys.push([1, 3, , 4]);
8491
+ return [4, this.program.methods
8492
+ .addInternalOracle({
8493
+ expo: exponent,
8494
+ extOracle: extOracleAccount,
8495
+ })
8496
+ .accountsPartial({
8497
+ admin: this.admin,
8498
+ multisig: this.multisig.publicKey,
8499
+ custodyTokenMint: tokenMint,
8500
+ intOracleAccount: intOracleAccount,
8501
+ systemProgram: web3_js_1.SystemProgram.programId,
8502
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY
8503
+ })
8504
+ .instruction()];
8505
+ case 2:
8506
+ addInternalOracleInstruction = _a.sent();
8507
+ instructions.push(addInternalOracleInstruction);
8508
+ return [3, 4];
8509
+ case 3:
8510
+ err_73 = _a.sent();
8511
+ console.log("perpClient setCustodyConfigInstruction error:: ", err_73);
8512
+ throw err_73;
8513
+ case 4: return [2, {
8514
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8515
+ additionalSigners: additionalSigners
8516
+ }];
8517
+ }
8518
+ });
8519
+ }); };
8520
+ this.setMarket = function (poolName, targetCustody, collateralCustody, marketAccount, maxPayoffBps, permissions, correlation) { return __awaiter(_this, void 0, void 0, function () {
8521
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setMarketConfigInstruction, err_74;
8522
+ return __generator(this, function (_a) {
8523
+ switch (_a.label) {
8524
+ case 0:
8525
+ publicKey = this.provider.wallet.publicKey;
8526
+ preInstructions = [];
8527
+ instructions = [];
8528
+ postInstructions = [];
8529
+ additionalSigners = [];
8530
+ _a.label = 1;
8531
+ case 1:
8532
+ _a.trys.push([1, 3, , 4]);
8533
+ return [4, this.program.methods
8534
+ .setMarketConfig({
8535
+ maxPayoffBps: maxPayoffBps,
8536
+ permissions: permissions,
8537
+ correlation: correlation
8538
+ })
8539
+ .accountsPartial({
8540
+ admin: this.admin,
8541
+ multisig: this.multisig.publicKey,
8542
+ market: marketAccount,
8543
+ targetCustody: targetCustody,
8544
+ collateralCustody: collateralCustody
8545
+ })
8546
+ .instruction()];
8547
+ case 2:
8548
+ setMarketConfigInstruction = _a.sent();
8549
+ instructions.push(setMarketConfigInstruction);
8550
+ return [3, 4];
8551
+ case 3:
8552
+ err_74 = _a.sent();
8553
+ console.log("perpClient setCustodyConfigInstruction error:: ", err_74);
8554
+ throw err_74;
8555
+ case 4: return [2, {
8556
+ instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8557
+ additionalSigners: additionalSigners
8558
+ }];
8559
+ }
8560
+ });
8561
+ }); };
8562
+ this.removeMarket = function (poolName, market, targetMint, collateralMint) { return __awaiter(_this, void 0, void 0, function () {
8563
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, removeMarketInstruction, err_75;
8564
+ return __generator(this, function (_a) {
8565
+ switch (_a.label) {
8566
+ case 0:
8567
+ publicKey = this.provider.wallet.publicKey;
8568
+ preInstructions = [];
8569
+ instructions = [];
8570
+ postInstructions = [];
8571
+ additionalSigners = [];
8572
+ _a.label = 1;
8573
+ case 1:
8574
+ _a.trys.push([1, 3, , 4]);
8575
+ return [4, this.program.methods
8576
+ .removeMarket({})
8577
+ .accountsPartial({
8578
+ admin: this.admin,
8579
+ multisig: this.multisig.publicKey,
8580
+ transferAuthority: this.authority.publicKey,
8581
+ perpetuals: this.perpetuals.publicKey,
8582
+ pool: this.getPoolKey(poolName),
8583
+ market: market,
8584
+ targetCustody: this.getCustodyKey(poolName, targetMint),
8585
+ collateralCustody: this.getCustodyKey(poolName, collateralMint),
8586
+ systemProgram: web3_js_1.SystemProgram.programId,
8587
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
8588
+ })
8589
+ .instruction()];
8590
+ case 2:
8591
+ removeMarketInstruction = _a.sent();
8592
+ instructions.push(removeMarketInstruction);
8593
+ return [3, 4];
8594
+ case 3:
8595
+ err_75 = _a.sent();
8596
+ console.log("perpClient setCustodyConfigInstruction error:: ", err_75);
8597
+ throw err_75;
7947
8598
  case 4: return [2, {
7948
8599
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7949
8600
  additionalSigners: additionalSigners
@@ -7953,18 +8604,14 @@ var PerpetualsClient = (function () {
7953
8604
  }); };
7954
8605
  this.provider = provider;
7955
8606
  (0, anchor_1.setProvider)(provider);
7956
- this.program = new anchor_1.Program(perpetuals_1.IDL, programId);
7957
- this.programPerpComposability = new anchor_1.Program(perp_composability_1.IDL, composabilityProgramId);
7958
- this.programFbnftReward = new anchor_1.Program(fbnft_rewards_1.IDL, fbNftRewardProgramId);
7959
- this.programRewardDistribution = new anchor_1.Program(reward_distribution_1.IDL, rewardDistributionProgramId);
8607
+ var idlWithAddress = __assign(__assign({}, perpetuals_json_1.default), { address: programId.toBase58() });
8608
+ this.program = new anchor_1.Program(idlWithAddress, provider);
7960
8609
  this.programId = programId;
7961
- this.composabilityProgramId = composabilityProgramId;
7962
8610
  this.admin = this.provider.wallet.publicKey;
7963
8611
  this.multisig = this.findProgramAddress("multisig");
7964
8612
  this.authority = this.findProgramAddress("transfer_authority");
7965
8613
  this.perpetuals = this.findProgramAddress("perpetuals");
7966
8614
  this.eventAuthority = this.findProgramAddress("__event_authority");
7967
- this.eventAuthorityRewardDistribution = this.findProgramAddressFromProgramId("__event_authority", null, this.programRewardDistribution.programId);
7968
8615
  this.minimumBalanceForRentExemptAccountLamports = 2039280;
7969
8616
  this.prioritizationFee = (opts === null || opts === void 0 ? void 0 : opts.prioritizationFee) || 0;
7970
8617
  this.useExtOracleAccount = useExtOracleAccount;
@@ -7979,7 +8626,7 @@ var PerpetualsClient = (function () {
7979
8626
  return this.findProgramAddress("market", [
7980
8627
  targetCustody,
7981
8628
  collateralCustody,
7982
- side === 'long' ? [1] : [2],
8629
+ (0, types_1.isVariant)(side, 'long') ? [1] : [2],
7983
8630
  ]).publicKey;
7984
8631
  };
7985
8632
  PerpetualsClient.prototype.getPositionKey = function (owner, targetCustody, collateralCustody, side) {