From 35ba8ad953739d42f88739ca63e13a077d7d890e Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 15 Jul 2025 17:38:05 +0000 Subject: [PATCH 1/2] Bumping drift-common to 113487b4986310590d2472f25c56f58ff77efcc5 --- drift-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drift-common b/drift-common index 20ae6b8..113487b 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit 20ae6b8f6d1d4a47e38e7ef70ee8e2574325d209 +Subproject commit 113487b4986310590d2472f25c56f58ff77efcc5 From 22aac5299491b7899790b9b8e1357fb5354a562e Mon Sep 17 00:00:00 2001 From: Nick Caradonna Date: Tue, 15 Jul 2025 14:47:04 -0400 Subject: [PATCH 2/2] auctionParams endpoint accept full precision amount param --- src/utils/tests/auctionParams.test.ts | 29 ++++++++++++++------------- src/utils/utils.ts | 7 ++----- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/utils/tests/auctionParams.test.ts b/src/utils/tests/auctionParams.test.ts index ab9ea1d..3eec8ce 100644 --- a/src/utils/tests/auctionParams.test.ts +++ b/src/utils/tests/auctionParams.test.ts @@ -5,7 +5,8 @@ import { MarketType, ZERO, QUOTE_PRECISION, - PRICE_PRECISION + PRICE_PRECISION, + BASE_PRECISION } from '@drift-labs/sdk'; import { createMarketBasedAuctionParams, @@ -191,7 +192,7 @@ describe('Auction Parameters Functions', () => { marketIndex: 0, marketType: 'perp' as any, direction: 'long' as any, - amount: '100', + amount: new BN(100).mul(BASE_PRECISION).toString(), // 100 in BASE_PRECISION assetType: 'base' as any, auctionDuration: 30, auctionStartPriceOffset: 0, @@ -261,6 +262,7 @@ describe('Auction Parameters Functions', () => { it('should handle quote-to-base conversion with realistic prices', async () => { const solPrice = 160; // $160 SOL price const quoteAmount = 1000; // $1,000 worth + const quoteAmountInPrecision = new BN(quoteAmount).mul(QUOTE_PRECISION); // Convert to quote precision mockDriftClient.getOracleDataForPerpMarket.mockReturnValue({ price: new BN(solPrice).mul(PRICE_PRECISION), @@ -282,7 +284,7 @@ describe('Auction Parameters Functions', () => { const quoteParams = { ...validParams, - amount: quoteAmount.toString(), + amount: quoteAmountInPrecision.toString(), assetType: 'quote' as any, }; @@ -300,10 +302,9 @@ describe('Auction Parameters Functions', () => { expect(baseAmount).toBeDefined(); expect(baseAmount.gt(ZERO)).toBe(true); - // Calculate expected base amount: (quoteAmount * QUOTE_PRECISION * BASE_PRECISION) / entryPrice - const expectedBaseAmount = new BN(quoteAmount) - .mul(QUOTE_PRECISION) - .mul(new BN(10).pow(new BN(9))) // BASE_PRECISION = 10^9 + // Calculate expected base amount: (amount * BASE_PRECISION) / entryPrice + const expectedBaseAmount = quoteAmountInPrecision + .mul(BASE_PRECISION) .div(result.data?.estimatedPrices.entryPrice); expect(baseAmount.toString()).toBe(expectedBaseAmount.toString()); @@ -414,7 +415,7 @@ describe('Auction Parameters Functions', () => { // Test small order const smallOrderParams = { ...validParams, - amount: '10', // Small order + amount: new BN(10).mul(BASE_PRECISION).toString(), // 10 in BASE_PRECISION }; const smallResult = await mapToMarketOrderParams( @@ -430,7 +431,7 @@ describe('Auction Parameters Functions', () => { // Test large order const largeOrderParams = { ...validParams, - amount: '1000', // Large order + amount: new BN(1000).mul(BASE_PRECISION).toString(), // 1000 in BASE_PRECISION }; const largeResult = await mapToMarketOrderParams( @@ -565,7 +566,7 @@ describe('Auction Parameters Functions', () => { marketIndex: 0, marketType: 'perp' as any, direction: 'long' as any, - amount: '100', + amount: new BN(100).mul(BASE_PRECISION).toString(), // 100 in BASE_PRECISION assetType: 'base' as any, auctionStartPriceOffsetFrom: 'marketBased' as any, auctionStartPriceOffset: 'marketBased' as any, @@ -578,7 +579,7 @@ describe('Auction Parameters Functions', () => { marketIndex: 5, marketType: 'perp' as any, direction: 'short' as any, - amount: '500', + amount: new BN(500).mul(QUOTE_PRECISION).toString(), // 500 in QUOTE_PRECISION assetType: 'quote' as any, auctionStartPriceOffsetFrom: 'marketBased' as any, auctionStartPriceOffset: 'marketBased' as any, @@ -591,7 +592,7 @@ describe('Auction Parameters Functions', () => { marketIndex: 2, marketType: 'spot' as any, direction: 'long' as any, - amount: '1000', + amount: new BN(1000).mul(BASE_PRECISION).toString(), // 1000 in BASE_PRECISION assetType: 'base' as any, auctionStartPriceOffsetFrom: 'marketBased' as any, auctionStartPriceOffset: 'marketBased' as any, @@ -621,7 +622,7 @@ describe('Auction Parameters Functions', () => { marketIndex: 0, // Major market - would normally get 'mark' and 0 marketType: 'perp' as any, direction: 'long' as any, - amount: '100', + amount: new BN(100).mul(BASE_PRECISION).toString(), // 100 in BASE_PRECISION assetType: 'base' as any, auctionStartPriceOffsetFrom: 'oracle' as any, // explicit value auctionStartPriceOffset: 0.25, // explicit value @@ -644,7 +645,7 @@ describe('Auction Parameters Functions', () => { marketIndex: 1, marketType: 'perp' as any, direction: 'long' as any, - amount: '100', + amount: new BN(100).mul(BASE_PRECISION).toString(), // 100 in BASE_PRECISION assetType: 'base' as any, auctionStartPriceOffsetFrom: 'marketBased' as any, auctionStartPriceOffset: 'marketBased' as any, diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 612f1a0..553c23f 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -889,11 +889,8 @@ export const mapToMarketOrderParams = async ( ? PositionDirection.LONG : PositionDirection.SHORT; - // Convert amount string to BN based on assetType - const amount = - params.assetType === 'base' - ? stringToBN(params.amount).mul(BASE_PRECISION) - : stringToBN(params.amount).mul(QUOTE_PRECISION); + // Convert amount string to BN - amount is already in base or quote precision + const amount = stringToBN(params.amount); // Convert additionalEndPriceBuffer string to BN with PRICE_PRECISION (1e6) if provided const additionalEndPriceBuffer = params.additionalEndPriceBuffer