use mm oracle

This commit is contained in:
Nour Alharithi
2025-07-29 11:30:11 -07:00
parent ff4a79c5b4
commit bb476e97f7
3 changed files with 26 additions and 20 deletions

View File

@@ -1,6 +1,10 @@
git submodule init
git submodule update --recursive
rm -rf node_modules
rm -rf drift-common/protocol/sdk/node_modules
rm -rf drift-common/common-ts/node_modules
echo "building sdk..."
cd drift-common/protocol/sdk
yarn clean && yarn && yarn build && yarn link

View File

@@ -13,7 +13,7 @@ import {
PerpOperation,
PositionDirection,
ZERO,
calculateBidAskPrice,
calculateAMMBidAskPrice,
getLimitPrice,
isOperationPaused,
isVariant,
@@ -177,9 +177,11 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
let bestBid = bestDlobBid;
let bestAsk = bestDlobAsk;
if (marketType === 'perp') {
const [bestVammBid, bestVammAsk] = calculateBidAskPrice(
const [bestVammBid, bestVammAsk] = calculateAMMBidAskPrice(
this.driftClient.getPerpMarketAccount(marketArgs.marketIndex).amm,
oraclePriceData,
this.driftClient.getMMOracleDataForPerpMarket(
marketArgs.marketIndex
),
true
);

View File

@@ -1,7 +1,7 @@
import {
BN,
BigNum,
DriftClient,
IDriftClient,
DriftEnv,
L2OrderBook,
L3OrderBook,
@@ -92,7 +92,7 @@ export function parsePositiveIntArray(
}
export const getOracleForMarket = (
driftClient: DriftClient,
driftClient: IDriftClient,
marketType: MarketType,
marketIndex: number
): number => {
@@ -129,7 +129,7 @@ const getSerializableOraclePriceData = (
};
export const getOracleDataForMarket = (
driftClient: DriftClient,
driftClient: IDriftClient,
marketType: MarketType,
marketIndex: number
): SerializableOraclePriceData => {
@@ -146,7 +146,7 @@ export const getOracleDataForMarket = (
export const addOracletoResponse = (
response: L2OrderBook | L3OrderBook,
driftClient: DriftClient,
driftClient: IDriftClient,
marketType: MarketType,
marketIndex: number
): void => {
@@ -177,7 +177,7 @@ export const addOracletoResponse = (
export const addMarketSlotToResponse = (
response: L2OrderBook | L3OrderBook,
driftClient: DriftClient,
driftClient: IDriftClient,
marketType: MarketType,
marketIndex: number
): void => {
@@ -418,7 +418,7 @@ export const validateWsSubscribeMsg = (
};
export const validateDlobQuery = (
driftClient: DriftClient,
driftClient: IDriftClient,
driftEnv: DriftEnv,
marketType?: string,
marketIndex?: string,
@@ -571,7 +571,7 @@ export function errorHandler(
*/
export const getPhoenixSubscriber = (
driftClient: DriftClient,
driftClient: IDriftClient,
marketConfig: SpotMarketConfig,
sdkConfig
): PhoenixSubscriber => {
@@ -586,7 +586,7 @@ export const getPhoenixSubscriber = (
};
export const getSerumSubscriber = (
driftClient: DriftClient,
driftClient: IDriftClient,
marketConfig: SpotMarketConfig,
sdkConfig
): SerumSubscriber => {
@@ -601,7 +601,7 @@ export const getSerumSubscriber = (
};
export const getOpenbookSubscriber = (
driftClient: DriftClient,
driftClient: IDriftClient,
marketConfig: SpotMarketConfig,
sdkConfig
): OpenbookV2Subscriber => {
@@ -748,7 +748,7 @@ export const convertRawL2ToBN = (rawL2: any): L2OrderBook => {
/**
* Get L2 orderbook data and calculate estimated prices
* @param driftClient - DriftClient instance
* @param driftClient - IDriftClient instance
* @param marketType - MarketType enum
* @param marketIndex - Market index number
* @param direction - Position direction
@@ -759,7 +759,7 @@ export const convertRawL2ToBN = (rawL2: any): L2OrderBook => {
* @returns Price data object with oracle, best, entry, worst, and mark prices
*/
export const getEstimatedPrices = async (
driftClient: DriftClient,
driftClient: IDriftClient,
marketType: MarketType,
marketIndex: number,
direction: PositionDirection,
@@ -857,14 +857,14 @@ export const getEstimatedPrices = async (
/**
* Maps AuctionParamArgs to the format expected by deriveMarketOrderParams
* @param params - AuctionParamArgs from the API request
* @param driftClient - DriftClient instance (optional, for price calculation)
* @param driftClient - IDriftClient instance (optional, for price calculation)
* @param fetchFromRedis - Redis fetch function (optional, for price calculation)
* @param selectMostRecentBySlot - Slot selection function (optional, for price calculation)
* @returns Object formatted for deriveMarketOrderParams function or error response
*/
export const mapToMarketOrderParams = async (
params: AuctionParamArgs,
driftClient?: DriftClient,
driftClient?: IDriftClient,
fetchFromRedis?: (
key: string,
selectionCriteria: (responses: any) => any
@@ -1064,14 +1064,14 @@ export const fetchL2FromRedis = async (
* @param direction - Position direction ('long' or 'short')
* @param marketIndex - Market index number
* @param marketType - Market type ('spot' or 'perp')
* @param driftClient - DriftClient instance for oracle data
* @param driftClient - IDriftClient instance for oracle data
* @param l2Formatted - Already formatted L2OrderBook data
* @returns Dynamic slippage tolerance as a number
*/
export const calculateDynamicSlippage = (
marketIndex: number,
marketType: string,
driftClient: DriftClient,
driftClient: IDriftClient,
l2Formatted: L2OrderBook
): number => {
// Determine if this is a major market (PERP with marketIndex 0, 1, or 2)
@@ -1128,7 +1128,7 @@ export const calculateDynamicSlippage = (
/**
* Get L2 orderbook data and calculate estimated prices using pre-fetched L2 data
* @param driftClient - DriftClient instance
* @param driftClient - IDriftClient instance
* @param marketType - MarketType enum
* @param marketIndex - Market index number
* @param direction - Position direction
@@ -1138,7 +1138,7 @@ export const calculateDynamicSlippage = (
* @returns Price data object with oracle, best, entry, worst, and mark prices
*/
export const getEstimatedPricesWithL2 = async (
driftClient: DriftClient,
driftClient: IDriftClient,
marketType: MarketType,
marketIndex: number,
direction: PositionDirection,