Merge remote-tracking branch 'origin/master' into wphan/health_check_fix

This commit is contained in:
wphan
2025-07-15 11:58:39 -07:00
3 changed files with 21 additions and 23 deletions

View File

@@ -6,6 +6,7 @@ import {
ZERO, ZERO,
QUOTE_PRECISION, QUOTE_PRECISION,
PRICE_PRECISION, PRICE_PRECISION,
BASE_PRECISION
} from '@drift-labs/sdk'; } from '@drift-labs/sdk';
import { import {
createMarketBasedAuctionParams, createMarketBasedAuctionParams,
@@ -191,7 +192,7 @@ describe('Auction Parameters Functions', () => {
marketIndex: 0, marketIndex: 0,
marketType: 'perp' as any, marketType: 'perp' as any,
direction: 'long' as any, direction: 'long' as any,
amount: '100', amount: new BN(100).mul(BASE_PRECISION).toString(), // 100 in BASE_PRECISION
assetType: 'base' as any, assetType: 'base' as any,
auctionDuration: 30, auctionDuration: 30,
auctionStartPriceOffset: 0, auctionStartPriceOffset: 0,
@@ -261,6 +262,7 @@ describe('Auction Parameters Functions', () => {
it('should handle quote-to-base conversion with realistic prices', async () => { it('should handle quote-to-base conversion with realistic prices', async () => {
const solPrice = 160; // $160 SOL price const solPrice = 160; // $160 SOL price
const quoteAmount = 1000; // $1,000 worth const quoteAmount = 1000; // $1,000 worth
const quoteAmountInPrecision = new BN(quoteAmount).mul(QUOTE_PRECISION); // Convert to quote precision
mockDriftClient.getOracleDataForPerpMarket.mockReturnValue({ mockDriftClient.getOracleDataForPerpMarket.mockReturnValue({
price: new BN(solPrice).mul(PRICE_PRECISION), price: new BN(solPrice).mul(PRICE_PRECISION),
@@ -282,7 +284,7 @@ describe('Auction Parameters Functions', () => {
const quoteParams = { const quoteParams = {
...validParams, ...validParams,
amount: quoteAmount.toString(), amount: quoteAmountInPrecision.toString(),
assetType: 'quote' as any, assetType: 'quote' as any,
}; };
@@ -300,10 +302,9 @@ describe('Auction Parameters Functions', () => {
expect(baseAmount).toBeDefined(); expect(baseAmount).toBeDefined();
expect(baseAmount.gt(ZERO)).toBe(true); expect(baseAmount.gt(ZERO)).toBe(true);
// Calculate expected base amount: (quoteAmount * QUOTE_PRECISION * BASE_PRECISION) / entryPrice // Calculate expected base amount: (amount * BASE_PRECISION) / entryPrice
const expectedBaseAmount = new BN(quoteAmount) const expectedBaseAmount = quoteAmountInPrecision
.mul(QUOTE_PRECISION) .mul(BASE_PRECISION)
.mul(new BN(10).pow(new BN(9))) // BASE_PRECISION = 10^9
.div(result.data?.estimatedPrices.entryPrice); .div(result.data?.estimatedPrices.entryPrice);
expect(baseAmount.toString()).toBe(expectedBaseAmount.toString()); expect(baseAmount.toString()).toBe(expectedBaseAmount.toString());
@@ -416,7 +417,7 @@ describe('Auction Parameters Functions', () => {
// Test small order // Test small order
const smallOrderParams = { const smallOrderParams = {
...validParams, ...validParams,
amount: '10', // Small order amount: new BN(10).mul(BASE_PRECISION).toString(), // 10 in BASE_PRECISION
}; };
const smallResult = await mapToMarketOrderParams( const smallResult = await mapToMarketOrderParams(
@@ -432,7 +433,7 @@ describe('Auction Parameters Functions', () => {
// Test large order // Test large order
const largeOrderParams = { const largeOrderParams = {
...validParams, ...validParams,
amount: '1000', // Large order amount: new BN(1000).mul(BASE_PRECISION).toString(), // 1000 in BASE_PRECISION
}; };
const largeResult = await mapToMarketOrderParams( const largeResult = await mapToMarketOrderParams(
@@ -571,7 +572,7 @@ describe('Auction Parameters Functions', () => {
marketIndex: 0, marketIndex: 0,
marketType: 'perp' as any, marketType: 'perp' as any,
direction: 'long' as any, direction: 'long' as any,
amount: '100', amount: new BN(100).mul(BASE_PRECISION).toString(), // 100 in BASE_PRECISION
assetType: 'base' as any, assetType: 'base' as any,
auctionStartPriceOffsetFrom: 'marketBased' as any, auctionStartPriceOffsetFrom: 'marketBased' as any,
auctionStartPriceOffset: 'marketBased' as any, auctionStartPriceOffset: 'marketBased' as any,
@@ -584,7 +585,7 @@ describe('Auction Parameters Functions', () => {
marketIndex: 5, marketIndex: 5,
marketType: 'perp' as any, marketType: 'perp' as any,
direction: 'short' as any, direction: 'short' as any,
amount: '500', amount: new BN(500).mul(QUOTE_PRECISION).toString(), // 500 in QUOTE_PRECISION
assetType: 'quote' as any, assetType: 'quote' as any,
auctionStartPriceOffsetFrom: 'marketBased' as any, auctionStartPriceOffsetFrom: 'marketBased' as any,
auctionStartPriceOffset: 'marketBased' as any, auctionStartPriceOffset: 'marketBased' as any,
@@ -597,7 +598,7 @@ describe('Auction Parameters Functions', () => {
marketIndex: 2, marketIndex: 2,
marketType: 'spot' as any, marketType: 'spot' as any,
direction: 'long' as any, direction: 'long' as any,
amount: '1000', amount: new BN(1000).mul(BASE_PRECISION).toString(), // 1000 in BASE_PRECISION
assetType: 'base' as any, assetType: 'base' as any,
auctionStartPriceOffsetFrom: 'marketBased' as any, auctionStartPriceOffsetFrom: 'marketBased' as any,
auctionStartPriceOffset: 'marketBased' as any, auctionStartPriceOffset: 'marketBased' as any,
@@ -631,7 +632,7 @@ describe('Auction Parameters Functions', () => {
marketIndex: 0, // Major market - would normally get 'mark' and 0 marketIndex: 0, // Major market - would normally get 'mark' and 0
marketType: 'perp' as any, marketType: 'perp' as any,
direction: 'long' as any, direction: 'long' as any,
amount: '100', amount: new BN(100).mul(BASE_PRECISION).toString(), // 100 in BASE_PRECISION
assetType: 'base' as any, assetType: 'base' as any,
auctionStartPriceOffsetFrom: 'oracle' as any, // explicit value auctionStartPriceOffsetFrom: 'oracle' as any, // explicit value
auctionStartPriceOffset: 0.25, // explicit value auctionStartPriceOffset: 0.25, // explicit value
@@ -654,7 +655,7 @@ describe('Auction Parameters Functions', () => {
marketIndex: 1, marketIndex: 1,
marketType: 'perp' as any, marketType: 'perp' as any,
direction: 'long' as any, direction: 'long' as any,
amount: '100', amount: new BN(100).mul(BASE_PRECISION).toString(), // 100 in BASE_PRECISION
assetType: 'base' as any, assetType: 'base' as any,
auctionStartPriceOffsetFrom: 'marketBased' as any, auctionStartPriceOffsetFrom: 'marketBased' as any,
auctionStartPriceOffset: 'marketBased' as any, auctionStartPriceOffset: 'marketBased' as any,

View File

@@ -891,11 +891,8 @@ export const mapToMarketOrderParams = async (
? PositionDirection.LONG ? PositionDirection.LONG
: PositionDirection.SHORT; : PositionDirection.SHORT;
// Convert amount string to BN based on assetType // Convert amount string to BN - amount is already in base or quote precision
const amount = const amount = stringToBN(params.amount);
params.assetType === 'base'
? stringToBN(params.amount).mul(BASE_PRECISION)
: stringToBN(params.amount).mul(QUOTE_PRECISION);
// Convert additionalEndPriceBuffer string to BN with PRICE_PRECISION (1e6) if provided // Convert additionalEndPriceBuffer string to BN with PRICE_PRECISION (1e6) if provided
const additionalEndPriceBuffer = params.additionalEndPriceBuffer const additionalEndPriceBuffer = params.additionalEndPriceBuffer