@drift-labs/sdk 2.52.0-beta.2 → 2.52.0-beta.3
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/user.d.ts +1 -1
- package/lib/user.js +14 -6
- package/package.json +1 -1
- package/src/user.ts +19 -6
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.52.0-beta.
|
|
1
|
+
2.52.0-beta.3
|
package/lib/user.d.ts
CHANGED
|
@@ -353,7 +353,7 @@ export declare class User {
|
|
|
353
353
|
* @param quoteAmount
|
|
354
354
|
* @returns feeForQuote : Precision QUOTE_PRECISION
|
|
355
355
|
*/
|
|
356
|
-
calculateFeeForQuoteAmount(quoteAmount: BN): BN;
|
|
356
|
+
calculateFeeForQuoteAmount(quoteAmount: BN, marketIndex?: number): BN;
|
|
357
357
|
/**
|
|
358
358
|
* Calculates a user's max withdrawal amounts for a spot market. If reduceOnly is true,
|
|
359
359
|
* it will return the max withdrawal amount without opening a liability for the user
|
package/lib/user.js
CHANGED
|
@@ -1645,7 +1645,7 @@ class User {
|
|
|
1645
1645
|
const feeTier = this.getUserFeeTier(marketType);
|
|
1646
1646
|
let takerFee = feeTier.feeNumerator / feeTier.feeDenominator;
|
|
1647
1647
|
let makerFee = feeTier.makerRebateNumerator / feeTier.makerRebateDenominator;
|
|
1648
|
-
if (marketIndex && (0, types_1.isVariant)(marketType, 'perp')) {
|
|
1648
|
+
if (marketIndex !== undefined && (0, types_1.isVariant)(marketType, 'perp')) {
|
|
1649
1649
|
const marketAccount = this.driftClient.getPerpMarketAccount(marketIndex);
|
|
1650
1650
|
takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
|
|
1651
1651
|
makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
|
|
@@ -1660,11 +1660,19 @@ class User {
|
|
|
1660
1660
|
* @param quoteAmount
|
|
1661
1661
|
* @returns feeForQuote : Precision QUOTE_PRECISION
|
|
1662
1662
|
*/
|
|
1663
|
-
calculateFeeForQuoteAmount(quoteAmount) {
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1663
|
+
calculateFeeForQuoteAmount(quoteAmount, marketIndex) {
|
|
1664
|
+
if (marketIndex !== undefined) {
|
|
1665
|
+
const takerFeeMultiplier = this.getMarketFees(_1.MarketType.PERP, marketIndex).takerFee;
|
|
1666
|
+
const feeAmountNum = _1.BigNum.from(quoteAmount, numericConstants_1.QUOTE_PRECISION_EXP).toNum() *
|
|
1667
|
+
takerFeeMultiplier;
|
|
1668
|
+
return _1.BigNum.fromPrint(feeAmountNum.toString(), numericConstants_1.QUOTE_PRECISION_EXP).val;
|
|
1669
|
+
}
|
|
1670
|
+
else {
|
|
1671
|
+
const feeTier = this.getUserFeeTier(_1.MarketType.PERP);
|
|
1672
|
+
return quoteAmount
|
|
1673
|
+
.mul(new _1.BN(feeTier.feeNumerator))
|
|
1674
|
+
.div(new _1.BN(feeTier.feeDenominator));
|
|
1675
|
+
}
|
|
1668
1676
|
}
|
|
1669
1677
|
/**
|
|
1670
1678
|
* Calculates a user's max withdrawal amounts for a spot market. If reduceOnly is true,
|
package/package.json
CHANGED
package/src/user.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
OPEN_ORDER_MARGIN_REQUIREMENT,
|
|
28
28
|
PRICE_PRECISION,
|
|
29
29
|
QUOTE_PRECISION,
|
|
30
|
+
QUOTE_PRECISION_EXP,
|
|
30
31
|
QUOTE_SPOT_MARKET_INDEX,
|
|
31
32
|
SPOT_MARKET_WEIGHT_PRECISION,
|
|
32
33
|
TEN,
|
|
@@ -40,6 +41,7 @@ import {
|
|
|
40
41
|
UserAccountSubscriber,
|
|
41
42
|
} from './accounts/types';
|
|
42
43
|
import {
|
|
44
|
+
BigNum,
|
|
43
45
|
BN,
|
|
44
46
|
calculateBaseAssetValue,
|
|
45
47
|
calculateMarketMarginRatio,
|
|
@@ -3013,7 +3015,7 @@ export class User {
|
|
|
3013
3015
|
let makerFee =
|
|
3014
3016
|
feeTier.makerRebateNumerator / feeTier.makerRebateDenominator;
|
|
3015
3017
|
|
|
3016
|
-
if (marketIndex && isVariant(marketType, 'perp')) {
|
|
3018
|
+
if (marketIndex !== undefined && isVariant(marketType, 'perp')) {
|
|
3017
3019
|
const marketAccount = this.driftClient.getPerpMarketAccount(marketIndex);
|
|
3018
3020
|
takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
|
|
3019
3021
|
makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
|
|
@@ -3030,11 +3032,22 @@ export class User {
|
|
|
3030
3032
|
* @param quoteAmount
|
|
3031
3033
|
* @returns feeForQuote : Precision QUOTE_PRECISION
|
|
3032
3034
|
*/
|
|
3033
|
-
public calculateFeeForQuoteAmount(quoteAmount: BN): BN {
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3035
|
+
public calculateFeeForQuoteAmount(quoteAmount: BN, marketIndex?: number): BN {
|
|
3036
|
+
if (marketIndex !== undefined) {
|
|
3037
|
+
const takerFeeMultiplier = this.getMarketFees(
|
|
3038
|
+
MarketType.PERP,
|
|
3039
|
+
marketIndex
|
|
3040
|
+
).takerFee;
|
|
3041
|
+
const feeAmountNum =
|
|
3042
|
+
BigNum.from(quoteAmount, QUOTE_PRECISION_EXP).toNum() *
|
|
3043
|
+
takerFeeMultiplier;
|
|
3044
|
+
return BigNum.fromPrint(feeAmountNum.toString(), QUOTE_PRECISION_EXP).val;
|
|
3045
|
+
} else {
|
|
3046
|
+
const feeTier = this.getUserFeeTier(MarketType.PERP);
|
|
3047
|
+
return quoteAmount
|
|
3048
|
+
.mul(new BN(feeTier.feeNumerator))
|
|
3049
|
+
.div(new BN(feeTier.feeDenominator));
|
|
3050
|
+
}
|
|
3038
3051
|
}
|
|
3039
3052
|
|
|
3040
3053
|
/**
|