flash-sdk 11.11.0 → 11.11.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.
@@ -689,7 +689,7 @@ var PerpetualsClient = (function () {
689
689
  currentMarginUsd = positionAccount.collateralUsd.sub(lossUsd);
690
690
  }
691
691
  else {
692
- currentMarginUsd = positionAccount.collateralUsd.add(pnl.profitUsd).sub(lossUsd);
692
+ currentMarginUsd = positionAccount.collateralUsd.add(pnl.netProfitUsd).sub(lossUsd);
693
693
  }
694
694
  if (currentMarginUsd.gt(constants_1.BN_ZERO)) {
695
695
  return positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(currentMarginUsd);
@@ -863,7 +863,7 @@ var PerpetualsClient = (function () {
863
863
  if (collateralDeltaAmount.isNeg() || sizeDeltaAmount.isNeg()) {
864
864
  throw new Error("Delta Amounts cannot be negative ");
865
865
  }
866
- if (resultingPositionAccount.collateralAmount.isNeg() || resultingPositionAccount.sizeAmount.isNeg()) {
866
+ if (resultingPositionAccount.collateralUsd.isNeg() || resultingPositionAccount.sizeAmount.isNeg()) {
867
867
  throw new Error("cannot remove/close more than collateral/Size");
868
868
  }
869
869
  var sizeUsd = targetPrice.getAssetAmountUsd(sizeDeltaAmount, targetCustodyAccount.decimals);
@@ -1044,7 +1044,7 @@ var PerpetualsClient = (function () {
1044
1044
  var totalFeesUsd = (exitFeeUsd.add(lockAndUnsettledFeeUsd));
1045
1045
  var currentCollateralUsd = positionDelta.collateralUsd;
1046
1046
  var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
1047
- var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(currentCollateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionDelta.lockedAmount, collateralCustodyAccount.decimals));
1047
+ var assetsUsd = anchor_1.BN.min(newPnl.netProfitUsd.add(currentCollateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionDelta.lockedAmount, collateralCustodyAccount.decimals));
1048
1048
  if (debugLogs) {
1049
1049
  console.log("assetsUsd.sub(liabilityUsd):", collateralCustodyAccount.decimals, assetsUsd.toString(), liabilityUsd.toString(), assetsUsd.sub(liabilityUsd).toString());
1050
1050
  }
@@ -1178,10 +1178,11 @@ var PerpetualsClient = (function () {
1178
1178
  var position = PositionAccount_1.PositionAccount.from(positionAccount.publicKey, __assign({}, positionAccount));
1179
1179
  var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(collateralPrice, collateralEmaPrice, collateralCustodyAccount);
1180
1180
  var newPnl = _this.getPnlSync(position, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
1181
- var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, positionAccount.collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
1181
+ var collateralAmount = collateralPrice.getTokenAmount(positionAccount.collateralUsd, collateralCustodyAccount.decimals);
1182
+ var exitPriceAndFee = _this.getExitPriceAndFeeSync(positionAccount, marketCorrelation, collateralAmount, positionAccount.sizeAmount, side, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp);
1182
1183
  var totalFeesUsd = (exitPriceAndFee.exitFeeUsd.add(exitPriceAndFee.borrowFeeUsd));
1183
1184
  var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
1184
- var assetsUsd = anchor_1.BN.min(newPnl.profitUsd.add(positionAccount.collateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionAccount.lockedAmount, collateralCustodyAccount.decimals));
1185
+ var assetsUsd = anchor_1.BN.min(newPnl.netProfitUsd.add(positionAccount.collateralUsd), collateralMinMaxPrice.max.getAssetAmountUsd(positionAccount.lockedAmount, collateralCustodyAccount.decimals));
1185
1186
  var closeAmountUsd, feesAmountUsd;
1186
1187
  if (assetsUsd.gt(liabilityUsd)) {
1187
1188
  closeAmountUsd = assetsUsd.sub(liabilityUsd);
@@ -1597,6 +1598,9 @@ var PerpetualsClient = (function () {
1597
1598
  return {
1598
1599
  profitUsd: constants_1.BN_ZERO,
1599
1600
  lossUsd: constants_1.BN_ZERO,
1601
+ priceImpactUsd: constants_1.BN_ZERO,
1602
+ maxPriceImpactUsd: constants_1.BN_ZERO,
1603
+ netProfitUsd: constants_1.BN_ZERO
1600
1604
  };
1601
1605
  }
1602
1606
  var side = poolConfig.getMarketConfigByPk(positionAccount.market).side;
@@ -1660,16 +1664,28 @@ var PerpetualsClient = (function () {
1660
1664
  if (!priceDiffProfit.exponent.eq(priceDiffLoss.exponent)) {
1661
1665
  throw new Error("exponent mistach");
1662
1666
  }
1667
+ var maxPriceImpactUsd = positionAccount.priceImpactUsd;
1663
1668
  if (priceDiffProfit.price.gt(constants_1.BN_ZERO)) {
1669
+ var grossProfitUsd = priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals);
1670
+ var priceImpactUsd = positionAccount.priceImpactUsd.gt(constants_1.BN_ZERO)
1671
+ ? anchor_1.BN.min(positionAccount.priceImpactUsd, grossProfitUsd)
1672
+ : constants_1.BN_ZERO;
1673
+ var netProfitUsd = grossProfitUsd.sub(priceImpactUsd);
1664
1674
  return {
1665
- profitUsd: priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
1675
+ profitUsd: grossProfitUsd,
1666
1676
  lossUsd: constants_1.BN_ZERO,
1677
+ priceImpactUsd: priceImpactUsd,
1678
+ maxPriceImpactUsd: maxPriceImpactUsd,
1679
+ netProfitUsd: netProfitUsd,
1667
1680
  };
1668
1681
  }
1669
1682
  else {
1670
1683
  return {
1671
1684
  profitUsd: constants_1.BN_ZERO,
1672
1685
  lossUsd: priceDiffLoss.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
1686
+ priceImpactUsd: constants_1.BN_ZERO,
1687
+ maxPriceImpactUsd: maxPriceImpactUsd,
1688
+ netProfitUsd: constants_1.BN_ZERO,
1673
1689
  };
1674
1690
  }
1675
1691
  };
@@ -1682,7 +1698,7 @@ var PerpetualsClient = (function () {
1682
1698
  timestamp: constants_1.BN_ZERO
1683
1699
  });
1684
1700
  return {
1685
- pnl: { profitUsd: constants_1.BN_ZERO, lossUsd: constants_1.BN_ZERO },
1701
+ pnl: { profitUsd: constants_1.BN_ZERO, lossUsd: constants_1.BN_ZERO, priceImpactUsd: constants_1.BN_ZERO, maxPriceImpactUsd: constants_1.BN_ZERO, netProfitUsd: constants_1.BN_ZERO },
1686
1702
  leverage: constants_1.BN_ZERO,
1687
1703
  liquidationPrice: zeroOraclePrice,
1688
1704
  fees: { exitFeeUsd: constants_1.BN_ZERO, exitFeeAmount: constants_1.BN_ZERO, lockAndUnsettledFeeUsd: constants_1.BN_ZERO }
@@ -1702,68 +1718,18 @@ var PerpetualsClient = (function () {
1702
1718
  if (!exitOraclePrice.exponent.eq(entryOraclePrice.exponent)) {
1703
1719
  throw new Error("exponent mismatch");
1704
1720
  }
1705
- var priceDiffProfit, priceDiffLoss;
1706
- var delay = targetCustodyAccount.pricing.delaySeconds;
1707
- if ((0, types_1.isVariant)(side, 'long')) {
1708
- if (exitOraclePrice.price.gt(entryOraclePrice.price)) {
1709
- if (currentTimestamp.gt(positionAccount.updateTime.add(delay))) {
1710
- priceDiffProfit = new OraclePrice_1.OraclePrice({ price: exitOraclePrice.price.sub(entryOraclePrice.price), exponent: exitOraclePrice.exponent, confidence: exitOraclePrice.confidence, timestamp: constants_1.BN_ZERO });
1711
- priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1712
- }
1713
- else {
1714
- if (positionAccount.referencePrice.price.gt(entryOraclePrice.price)) {
1715
- priceDiffProfit = new OraclePrice_1.OraclePrice({ price: positionAccount.referencePrice.price.sub(entryOraclePrice.price), exponent: entryOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1716
- priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1717
- }
1718
- else {
1719
- priceDiffProfit = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1720
- priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1721
- }
1722
- }
1723
- }
1724
- else {
1725
- priceDiffProfit = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1726
- priceDiffLoss = new OraclePrice_1.OraclePrice({ price: entryOraclePrice.price.sub(exitOraclePrice.price), exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1727
- }
1728
- }
1729
- else {
1730
- if (exitOraclePrice.price.lt(entryOraclePrice.price)) {
1731
- if (currentTimestamp.gt(positionAccount.updateTime.add(delay))) {
1732
- priceDiffProfit = new OraclePrice_1.OraclePrice({ price: entryOraclePrice.price.sub(exitOraclePrice.price), exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1733
- priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1734
- }
1735
- else {
1736
- if (entryOraclePrice.price.gt(positionAccount.referencePrice.price)) {
1737
- priceDiffProfit = new OraclePrice_1.OraclePrice({ price: entryOraclePrice.price.sub(positionAccount.referencePrice.price), exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1738
- priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1739
- }
1740
- else {
1741
- priceDiffProfit = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1742
- priceDiffLoss = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1743
- }
1744
- }
1745
- }
1746
- else {
1747
- priceDiffProfit = new OraclePrice_1.OraclePrice({ price: constants_1.BN_ZERO, exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1748
- priceDiffLoss = new OraclePrice_1.OraclePrice({ price: exitOraclePrice.price.sub(entryOraclePrice.price), exponent: exitOraclePrice.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
1749
- }
1750
- }
1751
- if (priceDiffProfit.price.gt(constants_1.BN_ZERO)) {
1752
- pnl = {
1753
- profitUsd: priceDiffProfit.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
1754
- lossUsd: constants_1.BN_ZERO,
1755
- };
1756
- }
1757
- else {
1758
- pnl = {
1759
- profitUsd: constants_1.BN_ZERO,
1760
- lossUsd: priceDiffLoss.getAssetAmountUsd(positionAccount.sizeAmount, positionAccount.sizeDecimals),
1761
- };
1762
- }
1721
+ var pnlResult = _this.getPnlContractHelper(positionAccount, targetTokenPrice, targetTokenEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, targetCustodyAccount.pricing.delaySeconds, poolConfig);
1722
+ pnl = {
1723
+ profitUsd: pnlResult.profitUsd,
1724
+ lossUsd: pnlResult.lossUsd,
1725
+ priceImpactUsd: pnlResult.priceImpactUsd,
1726
+ maxPriceImpactUsd: pnlResult.maxPriceImpactUsd,
1727
+ netProfitUsd: pnlResult.netProfitUsd
1728
+ };
1763
1729
  var liquidationPrice = _this.getLiquidationPriceContractHelper(entryOraclePrice, lockAndUnsettledFeeUsd, side, targetCustodyAccount, positionAccount);
1764
1730
  var unsettledFeesUsd = exitFeeUsd.add(lockAndUnsettledFeeUsd);
1765
1731
  var lossUsd = pnl.lossUsd.add(unsettledFeesUsd);
1766
- var currentMarginUsd = positionAccount.collateralUsd.add(pnl.profitUsd).sub(lossUsd);
1732
+ var currentMarginUsd = positionAccount.collateralUsd.add(pnl.netProfitUsd).sub(lossUsd);
1767
1733
  var leverage;
1768
1734
  if (currentMarginUsd.gt(constants_1.BN_ZERO)) {
1769
1735
  leverage = positionAccount.sizeUsd.mul(new anchor_1.BN(constants_1.BPS_POWER)).div(currentMarginUsd);
@@ -7599,8 +7565,44 @@ var PerpetualsClient = (function () {
7599
7565
  }
7600
7566
  });
7601
7567
  }); };
7568
+ this.setPositionPriceImpact = function (positionPubkey, priceImpactUsd, penaltyAuthority) { return __awaiter(_this, void 0, void 0, function () {
7569
+ var instructions, additionalSigners, setPositionPriceImpactIx, err_52;
7570
+ return __generator(this, function (_a) {
7571
+ switch (_a.label) {
7572
+ case 0:
7573
+ instructions = [];
7574
+ additionalSigners = [];
7575
+ _a.label = 1;
7576
+ case 1:
7577
+ _a.trys.push([1, 3, , 4]);
7578
+ return [4, this.program.methods
7579
+ .setPositionPriceImpact({
7580
+ priceImpactUsd: priceImpactUsd,
7581
+ })
7582
+ .accounts({
7583
+ authority: penaltyAuthority,
7584
+ position: positionPubkey,
7585
+ eventAuthority: this.eventAuthority.publicKey,
7586
+ program: this.program.programId,
7587
+ })
7588
+ .instruction()];
7589
+ case 2:
7590
+ setPositionPriceImpactIx = _a.sent();
7591
+ instructions.push(setPositionPriceImpactIx);
7592
+ return [3, 4];
7593
+ case 3:
7594
+ err_52 = _a.sent();
7595
+ console.log("perpClient setPositionPriceImpact error:: ", err_52);
7596
+ throw err_52;
7597
+ case 4: return [2, {
7598
+ instructions: __spreadArray([], instructions, true),
7599
+ additionalSigners: additionalSigners
7600
+ }];
7601
+ }
7602
+ });
7603
+ }); };
7602
7604
  this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7603
- var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_52;
7605
+ var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_53;
7604
7606
  return __generator(this, function (_a) {
7605
7607
  switch (_a.label) {
7606
7608
  case 0:
@@ -7638,8 +7640,8 @@ var PerpetualsClient = (function () {
7638
7640
  instructions.push(renameFlp);
7639
7641
  return [3, 4];
7640
7642
  case 3:
7641
- err_52 = _a.sent();
7642
- console.log("perpClient renameFlp error:: ", err_52);
7643
+ err_53 = _a.sent();
7644
+ console.log("perpClient renameFlp error:: ", err_53);
7643
7645
  return [3, 4];
7644
7646
  case 4: return [2, {
7645
7647
  instructions: __spreadArray([], instructions, true),
@@ -7649,7 +7651,7 @@ var PerpetualsClient = (function () {
7649
7651
  });
7650
7652
  }); };
7651
7653
  this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7652
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_53;
7654
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_54;
7653
7655
  return __generator(this, function (_a) {
7654
7656
  switch (_a.label) {
7655
7657
  case 0:
@@ -7687,9 +7689,9 @@ var PerpetualsClient = (function () {
7687
7689
  instructions.push(initStakeInstruction);
7688
7690
  return [3, 4];
7689
7691
  case 3:
7690
- err_53 = _a.sent();
7691
- console.log("perpClient InitStaking error:: ", err_53);
7692
- throw err_53;
7692
+ err_54 = _a.sent();
7693
+ console.log("perpClient InitStaking error:: ", err_54);
7694
+ throw err_54;
7693
7695
  case 4: return [2, {
7694
7696
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7695
7697
  additionalSigners: additionalSigners
@@ -7698,7 +7700,7 @@ var PerpetualsClient = (function () {
7698
7700
  });
7699
7701
  }); };
7700
7702
  this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7701
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_54;
7703
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_55;
7702
7704
  return __generator(this, function (_a) {
7703
7705
  switch (_a.label) {
7704
7706
  case 0:
@@ -7742,9 +7744,9 @@ var PerpetualsClient = (function () {
7742
7744
  instructions.push(initCompoundingInstruction);
7743
7745
  return [3, 4];
7744
7746
  case 3:
7745
- err_54 = _a.sent();
7746
- console.log("perpClient initCompounding error:: ", err_54);
7747
- throw err_54;
7747
+ err_55 = _a.sent();
7748
+ console.log("perpClient initCompounding error:: ", err_55);
7749
+ throw err_55;
7748
7750
  case 4: return [2, {
7749
7751
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7750
7752
  additionalSigners: additionalSigners
@@ -7753,7 +7755,7 @@ var PerpetualsClient = (function () {
7753
7755
  });
7754
7756
  }); };
7755
7757
  this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7756
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_55;
7758
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_56;
7757
7759
  return __generator(this, function (_a) {
7758
7760
  switch (_a.label) {
7759
7761
  case 0:
@@ -7794,9 +7796,9 @@ var PerpetualsClient = (function () {
7794
7796
  instructions.push(initTokenVaultInstruction);
7795
7797
  return [3, 4];
7796
7798
  case 3:
7797
- err_55 = _a.sent();
7798
- console.log("perpClient InitTokenVaultInstruction error:: ", err_55);
7799
- throw err_55;
7799
+ err_56 = _a.sent();
7800
+ console.log("perpClient InitTokenVaultInstruction error:: ", err_56);
7801
+ throw err_56;
7800
7802
  case 4: return [2, {
7801
7803
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7802
7804
  additionalSigners: additionalSigners
@@ -7805,7 +7807,7 @@ var PerpetualsClient = (function () {
7805
7807
  });
7806
7808
  }); };
7807
7809
  this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7808
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_56;
7810
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_57;
7809
7811
  return __generator(this, function (_a) {
7810
7812
  switch (_a.label) {
7811
7813
  case 0:
@@ -7836,9 +7838,9 @@ var PerpetualsClient = (function () {
7836
7838
  instructions.push(setTokenVaultConfigInstruction);
7837
7839
  return [3, 4];
7838
7840
  case 3:
7839
- err_56 = _a.sent();
7840
- console.log("perpClient setTokenVaultConfigInstruction error:: ", err_56);
7841
- throw err_56;
7841
+ err_57 = _a.sent();
7842
+ console.log("perpClient setTokenVaultConfigInstruction error:: ", err_57);
7843
+ throw err_57;
7842
7844
  case 4: return [2, {
7843
7845
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7844
7846
  additionalSigners: additionalSigners
@@ -7847,7 +7849,7 @@ var PerpetualsClient = (function () {
7847
7849
  });
7848
7850
  }); };
7849
7851
  this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7850
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_57;
7852
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_58;
7851
7853
  return __generator(this, function (_a) {
7852
7854
  switch (_a.label) {
7853
7855
  case 0:
@@ -7886,9 +7888,9 @@ var PerpetualsClient = (function () {
7886
7888
  instructions.push(withdrawInstantFeeInstruction);
7887
7889
  return [3, 6];
7888
7890
  case 5:
7889
- err_57 = _a.sent();
7890
- console.log("perpClient withdrawInstantFeeInstruction error:: ", err_57);
7891
- throw err_57;
7891
+ err_58 = _a.sent();
7892
+ console.log("perpClient withdrawInstantFeeInstruction error:: ", err_58);
7893
+ throw err_58;
7892
7894
  case 6: return [2, {
7893
7895
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7894
7896
  additionalSigners: additionalSigners
@@ -7897,7 +7899,7 @@ var PerpetualsClient = (function () {
7897
7899
  });
7898
7900
  }); };
7899
7901
  this.withdrawUnclaimedTokens = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7900
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawUnclaimedTokensInstruction, err_58;
7902
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawUnclaimedTokensInstruction, err_59;
7901
7903
  return __generator(this, function (_a) {
7902
7904
  switch (_a.label) {
7903
7905
  case 0:
@@ -7936,9 +7938,9 @@ var PerpetualsClient = (function () {
7936
7938
  instructions.push(withdrawUnclaimedTokensInstruction);
7937
7939
  return [3, 6];
7938
7940
  case 5:
7939
- err_58 = _a.sent();
7940
- console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_58);
7941
- throw err_58;
7941
+ err_59 = _a.sent();
7942
+ console.log("perpClient withdrawUnclaimedTokensInstruction error:: ", err_59);
7943
+ throw err_59;
7942
7944
  case 6: return [2, {
7943
7945
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7944
7946
  additionalSigners: additionalSigners
@@ -7947,7 +7949,7 @@ var PerpetualsClient = (function () {
7947
7949
  });
7948
7950
  }); };
7949
7951
  this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7950
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_59;
7952
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_60;
7951
7953
  return __generator(this, function (_a) {
7952
7954
  switch (_a.label) {
7953
7955
  case 0:
@@ -7984,9 +7986,9 @@ var PerpetualsClient = (function () {
7984
7986
  instructions.push(initRevenueTokenAccountInstruction);
7985
7987
  return [3, 4];
7986
7988
  case 3:
7987
- err_59 = _a.sent();
7988
- console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_59);
7989
- throw err_59;
7989
+ err_60 = _a.sent();
7990
+ console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_60);
7991
+ throw err_60;
7990
7992
  case 4: return [2, {
7991
7993
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
7992
7994
  additionalSigners: additionalSigners
@@ -7995,7 +7997,7 @@ var PerpetualsClient = (function () {
7995
7997
  });
7996
7998
  }); };
7997
7999
  this.initRebateVault = function (allowRebatePayout, rebateSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
7998
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateCustodyMint, initRebateVaultInstruction, err_60;
8000
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rebateCustodyMint, initRebateVaultInstruction, err_61;
7999
8001
  return __generator(this, function (_a) {
8000
8002
  switch (_a.label) {
8001
8003
  case 0:
@@ -8030,9 +8032,9 @@ var PerpetualsClient = (function () {
8030
8032
  instructions.push(initRebateVaultInstruction);
8031
8033
  return [3, 4];
8032
8034
  case 3:
8033
- err_60 = _a.sent();
8034
- console.log("perpClient initRebateVaultInstruction error:: ", err_60);
8035
- throw err_60;
8035
+ err_61 = _a.sent();
8036
+ console.log("perpClient initRebateVaultInstruction error:: ", err_61);
8037
+ throw err_61;
8036
8038
  case 4: return [2, {
8037
8039
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8038
8040
  additionalSigners: additionalSigners
@@ -8041,7 +8043,7 @@ var PerpetualsClient = (function () {
8041
8043
  });
8042
8044
  }); };
8043
8045
  this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
8044
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_61;
8046
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_62;
8045
8047
  return __generator(this, function (_a) {
8046
8048
  switch (_a.label) {
8047
8049
  case 0:
@@ -8080,9 +8082,9 @@ var PerpetualsClient = (function () {
8080
8082
  instructions.push(distributeTokenRewardInstruction);
8081
8083
  return [3, 4];
8082
8084
  case 3:
8083
- err_61 = _a.sent();
8084
- console.log("perpClient distributeTokenRewardInstruction error:: ", err_61);
8085
- throw err_61;
8085
+ err_62 = _a.sent();
8086
+ console.log("perpClient distributeTokenRewardInstruction error:: ", err_62);
8087
+ throw err_62;
8086
8088
  case 4: return [2, {
8087
8089
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8088
8090
  additionalSigners: additionalSigners
@@ -8091,7 +8093,7 @@ var PerpetualsClient = (function () {
8091
8093
  });
8092
8094
  }); };
8093
8095
  this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
8094
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_62;
8096
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_63;
8095
8097
  return __generator(this, function (_a) {
8096
8098
  switch (_a.label) {
8097
8099
  case 0:
@@ -8119,9 +8121,9 @@ var PerpetualsClient = (function () {
8119
8121
  instructions.push(setTokenStakeLevelInstruction);
8120
8122
  return [3, 4];
8121
8123
  case 3:
8122
- err_62 = _a.sent();
8123
- console.log("perpClient setTokenStakeLevelInstruction error:: ", err_62);
8124
- throw err_62;
8124
+ err_63 = _a.sent();
8125
+ console.log("perpClient setTokenStakeLevelInstruction error:: ", err_63);
8126
+ throw err_63;
8125
8127
  case 4: return [2, {
8126
8128
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8127
8129
  additionalSigners: additionalSigners
@@ -8130,7 +8132,7 @@ var PerpetualsClient = (function () {
8130
8132
  });
8131
8133
  }); };
8132
8134
  this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
8133
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_63;
8135
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_64;
8134
8136
  return __generator(this, function (_a) {
8135
8137
  switch (_a.label) {
8136
8138
  case 0:
@@ -8162,9 +8164,9 @@ var PerpetualsClient = (function () {
8162
8164
  instructions.push(setTokenRewardInstruction);
8163
8165
  return [3, 4];
8164
8166
  case 3:
8165
- err_63 = _a.sent();
8166
- console.log("perpClient setTokenRewardInstruction error:: ", err_63);
8167
- throw err_63;
8167
+ err_64 = _a.sent();
8168
+ console.log("perpClient setTokenRewardInstruction error:: ", err_64);
8169
+ throw err_64;
8168
8170
  case 4: return [2, {
8169
8171
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8170
8172
  additionalSigners: additionalSigners
@@ -8173,7 +8175,7 @@ var PerpetualsClient = (function () {
8173
8175
  });
8174
8176
  }); };
8175
8177
  this.resizeInternalOracle = function (extOracle, tokenMint, intOracleAccount) { return __awaiter(_this, void 0, void 0, function () {
8176
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_64;
8178
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, resizeInternalOracleInstruction, err_65;
8177
8179
  return __generator(this, function (_a) {
8178
8180
  switch (_a.label) {
8179
8181
  case 0:
@@ -8202,9 +8204,9 @@ var PerpetualsClient = (function () {
8202
8204
  instructions.push(resizeInternalOracleInstruction);
8203
8205
  return [3, 4];
8204
8206
  case 3:
8205
- err_64 = _a.sent();
8206
- console.log("perpClient resizeInternalOracleInstruction error:: ", err_64);
8207
- throw err_64;
8207
+ err_65 = _a.sent();
8208
+ console.log("perpClient resizeInternalOracleInstruction error:: ", err_65);
8209
+ throw err_65;
8208
8210
  case 4: return [2, {
8209
8211
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8210
8212
  additionalSigners: additionalSigners
@@ -8213,7 +8215,7 @@ var PerpetualsClient = (function () {
8213
8215
  });
8214
8216
  }); };
8215
8217
  this.createWhitelist = function (isSwapFeeExempt, isDepositFeeExempt, isWithdrawalFeeExempt, poolAddress, owner) { return __awaiter(_this, void 0, void 0, function () {
8216
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, whitelist, createWhitelistInstruction, err_65;
8218
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, whitelist, createWhitelistInstruction, err_66;
8217
8219
  return __generator(this, function (_a) {
8218
8220
  switch (_a.label) {
8219
8221
  case 0:
@@ -8246,9 +8248,9 @@ var PerpetualsClient = (function () {
8246
8248
  instructions.push(createWhitelistInstruction);
8247
8249
  return [3, 4];
8248
8250
  case 3:
8249
- err_65 = _a.sent();
8250
- console.log("perpClient createWhitelistInstruction error:: ", err_65);
8251
- throw err_65;
8251
+ err_66 = _a.sent();
8252
+ console.log("perpClient createWhitelistInstruction error:: ", err_66);
8253
+ throw err_66;
8252
8254
  case 4: return [2, {
8253
8255
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8254
8256
  additionalSigners: additionalSigners
@@ -8257,7 +8259,7 @@ var PerpetualsClient = (function () {
8257
8259
  });
8258
8260
  }); };
8259
8261
  this.setWhitelistConfig = function (isSwapFeeExempt, isDepositFeeExempt, isWithdrawalFeeExempt, poolAddress, owner) { return __awaiter(_this, void 0, void 0, function () {
8260
- var publicKey, preInstructions, instructions, postInstructions, additionalSigners, whitelist, setWhitelistConfigInstruction, err_66;
8262
+ var publicKey, preInstructions, instructions, postInstructions, additionalSigners, whitelist, setWhitelistConfigInstruction, err_67;
8261
8263
  return __generator(this, function (_a) {
8262
8264
  switch (_a.label) {
8263
8265
  case 0:
@@ -8290,9 +8292,9 @@ var PerpetualsClient = (function () {
8290
8292
  instructions.push(setWhitelistConfigInstruction);
8291
8293
  return [3, 4];
8292
8294
  case 3:
8293
- err_66 = _a.sent();
8294
- console.log("perpClient setWhitelistConfigInstruction error:: ", err_66);
8295
- throw err_66;
8295
+ err_67 = _a.sent();
8296
+ console.log("perpClient setWhitelistConfigInstruction error:: ", err_67);
8297
+ throw err_67;
8296
8298
  case 4: return [2, {
8297
8299
  instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
8298
8300
  additionalSigners: additionalSigners
@@ -14,14 +14,15 @@ export declare class PositionAccount implements Position {
14
14
  sizeAmount: BN;
15
15
  lockedAmount: BN;
16
16
  lockedUsd: BN;
17
- collateralAmount: BN;
17
+ priceImpactUsd: BN;
18
18
  collateralUsd: BN;
19
19
  unsettledValueUsd: BN;
20
20
  unsettledFeesUsd: BN;
21
21
  cumulativeLockFeeSnapshot: BN;
22
22
  degenSizeUsd: BN;
23
23
  referencePrice: ContractOraclePrice;
24
- buffer: number;
24
+ buffer: number[];
25
+ priceImpactSet: boolean;
25
26
  sizeDecimals: number;
26
27
  lockedDecimals: number;
27
28
  collateralDecimals: number;