@drift-labs/sdk 2.60.0-beta.12 → 2.60.0-beta.13

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.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.60.0-beta.12
1
+ 2.60.0-beta.13
package/lib/user.js CHANGED
@@ -1136,6 +1136,8 @@ class User {
1136
1136
  freeCollateralChange = costBasis.sub(newPositionValue);
1137
1137
  }
1138
1138
  else {
1139
+ console.log('newPositionValue', newPositionValue.toString());
1140
+ console.log('costBasis', costBasis.toString());
1139
1141
  freeCollateralChange = newPositionValue.sub(costBasis);
1140
1142
  }
1141
1143
  // assume worst fee tier
@@ -1146,17 +1148,12 @@ class User {
1146
1148
  freeCollateralChange = freeCollateralChange.sub(takerFee);
1147
1149
  }
1148
1150
  const worstCaseBaseAssetAmount = (0, margin_1.calculateWorstCaseBaseAssetAmount)(perpPosition);
1149
- const marginRatioBefore = (0, _1.calculateMarketMarginRatio)(market, worstCaseBaseAssetAmount.abs(), 'Maintenance');
1150
1151
  const newWorstCaseBaseAssetAmount = worstCaseBaseAssetAmount.add(positionBaseSizeChange);
1151
1152
  const newMarginRatio = (0, _1.calculateMarketMarginRatio)(market, newWorstCaseBaseAssetAmount.abs(), 'Maintenance');
1152
- // update free collateral to account for change in margin ratio from position change
1153
- freeCollateralChange = freeCollateralChange.sub(worstCaseBaseAssetAmount
1154
- .mul(oraclePrice)
1155
- .div(numericConstants_1.BASE_PRECISION)
1156
- .mul(new _1.BN(newMarginRatio - marginRatioBefore))
1157
- .div(numericConstants_1.MARGIN_PRECISION));
1158
1153
  // update free collateral to account for new margin requirement from position change
1159
- freeCollateralChange = freeCollateralChange.sub(positionBaseSizeChange
1154
+ freeCollateralChange = freeCollateralChange.sub(newWorstCaseBaseAssetAmount
1155
+ .abs()
1156
+ .sub(worstCaseBaseAssetAmount.abs())
1160
1157
  .mul(oraclePrice)
1161
1158
  .div(numericConstants_1.BASE_PRECISION)
1162
1159
  .mul(new _1.BN(newMarginRatio))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.60.0-beta.12",
3
+ "version": "2.60.0-beta.13",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
package/src/user.ts CHANGED
@@ -2092,6 +2092,8 @@ export class User {
2092
2092
  if (positionBaseSizeChange.gt(ZERO)) {
2093
2093
  freeCollateralChange = costBasis.sub(newPositionValue);
2094
2094
  } else {
2095
+ console.log('newPositionValue', newPositionValue.toString());
2096
+ console.log('costBasis', costBasis.toString());
2095
2097
  freeCollateralChange = newPositionValue.sub(costBasis);
2096
2098
  }
2097
2099
 
@@ -2107,12 +2109,6 @@ export class User {
2107
2109
  const worstCaseBaseAssetAmount =
2108
2110
  calculateWorstCaseBaseAssetAmount(perpPosition);
2109
2111
 
2110
- const marginRatioBefore = calculateMarketMarginRatio(
2111
- market,
2112
- worstCaseBaseAssetAmount.abs(),
2113
- 'Maintenance'
2114
- );
2115
-
2116
2112
  const newWorstCaseBaseAssetAmount = worstCaseBaseAssetAmount.add(
2117
2113
  positionBaseSizeChange
2118
2114
  );
@@ -2123,18 +2119,11 @@ export class User {
2123
2119
  'Maintenance'
2124
2120
  );
2125
2121
 
2126
- // update free collateral to account for change in margin ratio from position change
2127
- freeCollateralChange = freeCollateralChange.sub(
2128
- worstCaseBaseAssetAmount
2129
- .mul(oraclePrice)
2130
- .div(BASE_PRECISION)
2131
- .mul(new BN(newMarginRatio - marginRatioBefore))
2132
- .div(MARGIN_PRECISION)
2133
- );
2134
-
2135
2122
  // update free collateral to account for new margin requirement from position change
2136
2123
  freeCollateralChange = freeCollateralChange.sub(
2137
- positionBaseSizeChange
2124
+ newWorstCaseBaseAssetAmount
2125
+ .abs()
2126
+ .sub(worstCaseBaseAssetAmount.abs())
2138
2127
  .mul(oraclePrice)
2139
2128
  .div(BASE_PRECISION)
2140
2129
  .mul(new BN(newMarginRatio))