@drift-labs/sdk 2.143.0-beta.8 → 2.143.0
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/adminClient.d.ts +2 -2
- package/lib/browser/adminClient.js +5 -5
- package/lib/browser/dlob/DLOB.d.ts +9 -3
- package/lib/browser/dlob/DLOB.js +10 -13
- package/lib/browser/idl/drift.json +19 -23
- package/lib/browser/math/auction.d.ts +3 -2
- package/lib/browser/math/auction.js +23 -4
- package/lib/browser/math/oracles.d.ts +2 -1
- package/lib/browser/math/oracles.js +55 -1
- package/lib/browser/math/orders.d.ts +3 -2
- package/lib/browser/math/orders.js +13 -3
- package/lib/browser/types.d.ts +12 -1
- package/lib/browser/types.js +12 -1
- package/lib/node/adminClient.d.ts +2 -2
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +5 -5
- package/lib/node/dlob/DLOB.d.ts +9 -3
- package/lib/node/dlob/DLOB.d.ts.map +1 -1
- package/lib/node/dlob/DLOB.js +10 -13
- package/lib/node/idl/drift.json +19 -23
- package/lib/node/math/auction.d.ts +3 -2
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/auction.js +23 -4
- package/lib/node/math/oracles.d.ts +2 -1
- package/lib/node/math/oracles.d.ts.map +1 -1
- package/lib/node/math/oracles.js +55 -1
- package/lib/node/math/orders.d.ts +3 -2
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +13 -3
- package/lib/node/types.d.ts +12 -1
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/types.js +12 -1
- package/package.json +1 -1
- package/src/adminClient.ts +10 -10
- package/src/dlob/DLOB.ts +28 -15
- package/src/idl/drift.json +20 -24
- package/src/math/auction.ts +50 -7
- package/src/math/oracles.ts +88 -0
- package/src/math/orders.ts +30 -2
- package/src/types.ts +13 -1
- package/tests/dlob/helpers.ts +4 -4
package/src/math/orders.ts
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
PositionDirection,
|
|
9
9
|
ProtectedMakerParams,
|
|
10
10
|
MarketTypeStr,
|
|
11
|
+
OrderBitFlag,
|
|
12
|
+
StateAccount,
|
|
11
13
|
} from '../types';
|
|
12
14
|
import {
|
|
13
15
|
ZERO,
|
|
@@ -243,10 +245,16 @@ export function isFillableByVAMM(
|
|
|
243
245
|
mmOraclePriceData: MMOraclePriceData,
|
|
244
246
|
slot: number,
|
|
245
247
|
ts: number,
|
|
246
|
-
|
|
248
|
+
state: StateAccount
|
|
247
249
|
): boolean {
|
|
248
250
|
return (
|
|
249
|
-
(isFallbackAvailableLiquiditySource(
|
|
251
|
+
(isFallbackAvailableLiquiditySource(
|
|
252
|
+
order,
|
|
253
|
+
mmOraclePriceData,
|
|
254
|
+
slot,
|
|
255
|
+
state,
|
|
256
|
+
market
|
|
257
|
+
) &&
|
|
250
258
|
calculateBaseAssetAmountForAmmToFulfill(
|
|
251
259
|
order,
|
|
252
260
|
market,
|
|
@@ -257,6 +265,26 @@ export function isFillableByVAMM(
|
|
|
257
265
|
);
|
|
258
266
|
}
|
|
259
267
|
|
|
268
|
+
export function isLowRiskForAmm(
|
|
269
|
+
order: Order,
|
|
270
|
+
mmOraclePriceData: MMOraclePriceData,
|
|
271
|
+
isLiquidation?: boolean
|
|
272
|
+
): boolean {
|
|
273
|
+
if (isVariant(order.marketType, 'spot')) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const orderOlderThanOracleDelay = new BN(order.slot).lte(
|
|
278
|
+
mmOraclePriceData.slot
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
orderOlderThanOracleDelay ||
|
|
283
|
+
isLiquidation ||
|
|
284
|
+
(order.bitFlags & OrderBitFlag.SafeTriggerOrder) !== 0
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
260
288
|
export function calculateBaseAssetAmountForAmmToFulfill(
|
|
261
289
|
order: Order,
|
|
262
290
|
market: PerpMarketAccount,
|
package/src/types.ts
CHANGED
|
@@ -1107,7 +1107,8 @@ export type AMM = {
|
|
|
1107
1107
|
quoteAssetAmountWithUnsettledLp: BN;
|
|
1108
1108
|
referencePriceOffset: number;
|
|
1109
1109
|
|
|
1110
|
-
|
|
1110
|
+
oracleLowRiskSlotDelayOverride: number;
|
|
1111
|
+
oracleSlotDelayOverride: number;
|
|
1111
1112
|
ammSpreadAdjustment: number;
|
|
1112
1113
|
ammInventorySpreadAdjustment: number;
|
|
1113
1114
|
|
|
@@ -1473,6 +1474,17 @@ export type OracleGuardRails = {
|
|
|
1473
1474
|
};
|
|
1474
1475
|
};
|
|
1475
1476
|
|
|
1477
|
+
export enum OracleValidity {
|
|
1478
|
+
NonPositive = 0,
|
|
1479
|
+
TooVolatile = 1,
|
|
1480
|
+
TooUncertain = 2,
|
|
1481
|
+
StaleForMargin = 3,
|
|
1482
|
+
InsufficientDataPoints = 4,
|
|
1483
|
+
StaleForAMMLowRisk = 5,
|
|
1484
|
+
isStaleForAmmImmediate = 6,
|
|
1485
|
+
Valid = 7,
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1476
1488
|
export type PrelaunchOracle = {
|
|
1477
1489
|
price: BN;
|
|
1478
1490
|
maxPrice: BN;
|
package/tests/dlob/helpers.ts
CHANGED
|
@@ -145,7 +145,7 @@ export const mockAMM: AMM = {
|
|
|
145
145
|
quoteAssetAmountWithUnsettledLp: new BN(0),
|
|
146
146
|
referencePriceOffset: 0,
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
oracleLowRiskSlotDelayOverride: 0,
|
|
149
149
|
ammSpreadAdjustment: 0,
|
|
150
150
|
ammInventorySpreadAdjustment: 0,
|
|
151
151
|
mmOracleSequenceId: new BN(0),
|
|
@@ -672,9 +672,9 @@ export class MockUserMap implements UserMapInterface {
|
|
|
672
672
|
});
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
-
public async subscribe(): Promise<void> {}
|
|
675
|
+
public async subscribe(): Promise<void> { }
|
|
676
676
|
|
|
677
|
-
public async unsubscribe(): Promise<void> {}
|
|
677
|
+
public async unsubscribe(): Promise<void> { }
|
|
678
678
|
|
|
679
679
|
public async addPubkey(userAccountPublicKey: PublicKey): Promise<void> {
|
|
680
680
|
const user = new User({
|
|
@@ -733,7 +733,7 @@ export class MockUserMap implements UserMapInterface {
|
|
|
733
733
|
);
|
|
734
734
|
}
|
|
735
735
|
|
|
736
|
-
public async updateWithOrderRecord(_record: OrderRecord): Promise<void> {}
|
|
736
|
+
public async updateWithOrderRecord(_record: OrderRecord): Promise<void> { }
|
|
737
737
|
|
|
738
738
|
public values(): IterableIterator<User> {
|
|
739
739
|
return this.userMap.values();
|