@drift-labs/sdk 0.1.36-master.0 → 0.1.36-master.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/lib/accounts/pollingClearingHouseAccountSubscriber.js +10 -2
- package/lib/accounts/pollingOracleSubscriber.d.ts +1 -0
- package/lib/accounts/pollingOracleSubscriber.js +15 -4
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +1 -0
- package/lib/accounts/pollingTokenAccountSubscriber.js +15 -4
- package/lib/accounts/pollingUserAccountSubscriber.js +7 -2
- package/lib/idl/clearing_house.json +286 -286
- package/lib/math/amm.d.ts +1 -0
- package/lib/math/amm.js +16 -3
- package/lib/math/state.d.ts +8 -0
- package/lib/math/state.js +15 -0
- package/package.json +1 -1
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +12 -2
- package/src/accounts/pollingOracleSubscriber.ts +18 -4
- package/src/accounts/pollingTokenAccountSubscriber.ts +17 -4
- package/src/accounts/pollingUserAccountSubscriber.ts +7 -2
- package/src/idl/clearing_house.json +286 -286
- package/src/math/amm.ts +20 -2
- package/src/math/state.ts +14 -0
package/src/math/amm.ts
CHANGED
|
@@ -98,6 +98,22 @@ export function calculateAmmReservesAfterSwap(
|
|
|
98
98
|
return [newQuoteAssetReserve, newBaseAssetReserve];
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
export function calculateSpread(
|
|
102
|
+
amm: AMM,
|
|
103
|
+
direction: PositionDirection
|
|
104
|
+
): number {
|
|
105
|
+
let spread;
|
|
106
|
+
|
|
107
|
+
// future logic
|
|
108
|
+
if (isVariant(direction, 'long')) {
|
|
109
|
+
spread = amm.baseSpread;
|
|
110
|
+
} else {
|
|
111
|
+
spread = amm.baseSpread;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return spread;
|
|
115
|
+
}
|
|
116
|
+
|
|
101
117
|
export function calculateSpreadReserves(
|
|
102
118
|
amm: AMM,
|
|
103
119
|
direction: PositionDirection
|
|
@@ -105,7 +121,9 @@ export function calculateSpreadReserves(
|
|
|
105
121
|
baseAssetReserve: BN;
|
|
106
122
|
quoteAssetReserve: BN;
|
|
107
123
|
} {
|
|
108
|
-
|
|
124
|
+
const spread = calculateSpread(amm, direction);
|
|
125
|
+
|
|
126
|
+
if (spread === 0) {
|
|
109
127
|
return {
|
|
110
128
|
baseAssetReserve: amm.baseAssetReserve,
|
|
111
129
|
quoteAssetReserve: amm.quoteAssetReserve,
|
|
@@ -113,7 +131,7 @@ export function calculateSpreadReserves(
|
|
|
113
131
|
}
|
|
114
132
|
|
|
115
133
|
const quoteAsserReserveDelta = amm.quoteAssetReserve.div(
|
|
116
|
-
BID_ASK_SPREAD_PRECISION.div(new BN(
|
|
134
|
+
BID_ASK_SPREAD_PRECISION.div(new BN(spread / 4))
|
|
117
135
|
);
|
|
118
136
|
|
|
119
137
|
let quoteAssetReserve;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StateAccount } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get the clearing house percent fee charged on notional of taking trades
|
|
5
|
+
*
|
|
6
|
+
* @param state
|
|
7
|
+
* @returns Precision : basis points (bps)
|
|
8
|
+
*/
|
|
9
|
+
export function getExchangeFee(state: StateAccount): number {
|
|
10
|
+
const exchangeFee =
|
|
11
|
+
state.feeStructure.feeNumerator.toNumber() /
|
|
12
|
+
state.feeStructure.feeDenominator.toNumber();
|
|
13
|
+
return exchangeFee;
|
|
14
|
+
}
|