@drift-labs/sdk 2.102.0-beta.3 → 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 +1 -1
- package/lib/browser/user.js +3 -1
- package/lib/node/user.js +3 -1
- package/package.json +1 -1
- package/src/user.ts +14 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.102.0-beta.
|
|
1
|
+
2.102.0-beta.4
|
package/lib/browser/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
|
-
|
|
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/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
|
-
|
|
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
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
|
-
|
|
2977
|
+
inAssetWeight.lt(outAssetWeight);
|
|
2965
2978
|
|
|
2966
2979
|
if (freeCollateral.lt(PRICE_PRECISION.divn(100))) {
|
|
2967
2980
|
if (outSaferThanIn && inTokenAmount.gt(ZERO)) {
|