@drift-labs/sdk 2.102.0-beta.2 → 2.102.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.102.0-beta.2
1
+ 2.102.0-beta.4
@@ -369,7 +369,7 @@ exports.MainnetSpotMarkets = [
369
369
  symbol: 'USDS',
370
370
  marketIndex: 28,
371
371
  oracle: new web3_js_1.PublicKey('7pT9mxKXyvfaZKeKy1oe2oV2K1RFtF7tPEJHUY3h2vVV'),
372
- oracleSource: __1.OracleSource.PYTH_PULL,
372
+ oracleSource: __1.OracleSource.PYTH_STABLE_COIN_PULL,
373
373
  mint: new web3_js_1.PublicKey('USDSwr9ApdHk5bvJKMjzff41FfuX8bSxdKcR81vTwcA'),
374
374
  precision: new __1.BN(10).pow(numericConstants_1.SIX),
375
375
  precisionExp: numericConstants_1.SIX,
@@ -1558,11 +1558,13 @@ class User {
1558
1558
  let outSwap = numericConstants_1.ZERO;
1559
1559
  const inTokenAmount = this.getTokenAmount(inMarketIndex);
1560
1560
  const outTokenAmount = this.getTokenAmount(outMarketIndex);
1561
+ const inAssetWeight = (0, spotBalance_1.calculateAssetWeight)(inTokenAmount, inOraclePriceData.price, inMarket, 'Initial');
1562
+ const outAssetWeight = (0, spotBalance_1.calculateAssetWeight)(outTokenAmount, outOraclePriceData.price, outMarket, 'Initial');
1561
1563
  const outSaferThanIn =
1562
1564
  // selling asset to close borrow
1563
1565
  (inTokenAmount.gt(numericConstants_1.ZERO) && outTokenAmount.lt(numericConstants_1.ZERO)) ||
1564
1566
  // buying asset with higher initial asset weight
1565
- inMarket.initialAssetWeight < outMarket.initialAssetWeight;
1567
+ inAssetWeight.lt(outAssetWeight);
1566
1568
  if (freeCollateral.lt(numericConstants_1.PRICE_PRECISION.divn(100))) {
1567
1569
  if (outSaferThanIn && inTokenAmount.gt(numericConstants_1.ZERO)) {
1568
1570
  inSwap = inTokenAmount;
@@ -369,7 +369,7 @@ exports.MainnetSpotMarkets = [
369
369
  symbol: 'USDS',
370
370
  marketIndex: 28,
371
371
  oracle: new web3_js_1.PublicKey('7pT9mxKXyvfaZKeKy1oe2oV2K1RFtF7tPEJHUY3h2vVV'),
372
- oracleSource: __1.OracleSource.PYTH_PULL,
372
+ oracleSource: __1.OracleSource.PYTH_STABLE_COIN_PULL,
373
373
  mint: new web3_js_1.PublicKey('USDSwr9ApdHk5bvJKMjzff41FfuX8bSxdKcR81vTwcA'),
374
374
  precision: new __1.BN(10).pow(numericConstants_1.SIX),
375
375
  precisionExp: numericConstants_1.SIX,
package/lib/node/user.js CHANGED
@@ -1558,11 +1558,13 @@ class User {
1558
1558
  let outSwap = numericConstants_1.ZERO;
1559
1559
  const inTokenAmount = this.getTokenAmount(inMarketIndex);
1560
1560
  const outTokenAmount = this.getTokenAmount(outMarketIndex);
1561
+ const inAssetWeight = (0, spotBalance_1.calculateAssetWeight)(inTokenAmount, inOraclePriceData.price, inMarket, 'Initial');
1562
+ const outAssetWeight = (0, spotBalance_1.calculateAssetWeight)(outTokenAmount, outOraclePriceData.price, outMarket, 'Initial');
1561
1563
  const outSaferThanIn =
1562
1564
  // selling asset to close borrow
1563
1565
  (inTokenAmount.gt(numericConstants_1.ZERO) && outTokenAmount.lt(numericConstants_1.ZERO)) ||
1564
1566
  // buying asset with higher initial asset weight
1565
- inMarket.initialAssetWeight < outMarket.initialAssetWeight;
1567
+ inAssetWeight.lt(outAssetWeight);
1566
1568
  if (freeCollateral.lt(numericConstants_1.PRICE_PRECISION.divn(100))) {
1567
1569
  if (outSaferThanIn && inTokenAmount.gt(numericConstants_1.ZERO)) {
1568
1570
  inSwap = inTokenAmount;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.102.0-beta.2",
3
+ "version": "2.102.0-beta.4",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -454,7 +454,7 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
454
454
  symbol: 'USDS',
455
455
  marketIndex: 28,
456
456
  oracle: new PublicKey('7pT9mxKXyvfaZKeKy1oe2oV2K1RFtF7tPEJHUY3h2vVV'),
457
- oracleSource: OracleSource.PYTH_PULL,
457
+ oracleSource: OracleSource.PYTH_STABLE_COIN_PULL,
458
458
  mint: new PublicKey('USDSwr9ApdHk5bvJKMjzff41FfuX8bSxdKcR81vTwcA'),
459
459
  precision: new BN(10).pow(SIX),
460
460
  precisionExp: SIX,
package/src/user.ts CHANGED
@@ -2957,11 +2957,24 @@ export class User {
2957
2957
  const inTokenAmount = this.getTokenAmount(inMarketIndex);
2958
2958
  const outTokenAmount = this.getTokenAmount(outMarketIndex);
2959
2959
 
2960
+ const inAssetWeight = calculateAssetWeight(
2961
+ inTokenAmount,
2962
+ inOraclePriceData.price,
2963
+ inMarket,
2964
+ 'Initial'
2965
+ );
2966
+ const outAssetWeight = calculateAssetWeight(
2967
+ outTokenAmount,
2968
+ outOraclePriceData.price,
2969
+ outMarket,
2970
+ 'Initial'
2971
+ );
2972
+
2960
2973
  const outSaferThanIn =
2961
2974
  // selling asset to close borrow
2962
2975
  (inTokenAmount.gt(ZERO) && outTokenAmount.lt(ZERO)) ||
2963
2976
  // buying asset with higher initial asset weight
2964
- inMarket.initialAssetWeight < outMarket.initialAssetWeight;
2977
+ inAssetWeight.lt(outAssetWeight);
2965
2978
 
2966
2979
  if (freeCollateral.lt(PRICE_PRECISION.divn(100))) {
2967
2980
  if (outSaferThanIn && inTokenAmount.gt(ZERO)) {