Skip to content

Commit

Permalink
fix: price directions are dependent on buy mode and token order
Browse files Browse the repository at this point in the history
  • Loading branch information
dib542 committed Apr 7, 2024
1 parent 6484db3 commit 4872f87
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/components/cards/LimitOrderCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
mapEventAttributes,
} from '../../lib/web3/utils/events';
import { displayPriceToTickIndex } from '../../lib/web3/utils/ticks';
import { guessInvertedOrder } from '../../lib/web3/utils/pairs';

import Drawer from '../Drawer';

Expand Down Expand Up @@ -328,17 +329,17 @@ function LimitOrder({
) {
// when buying: select tick index below the limit
// when selling: select tick index above the limit
const rounding = buyMode ? 'floor' : 'ceil';
const limitTickIndexInToOut =
limitPrice > 0
? displayPriceToTickIndex(
new BigNumber(limitPrice),
tokenOut,
tokenIn,
rounding
// change limit rounding direction depending on token direction
guessInvertedOrder([denomIn, denomOut]) ? 'floor' : 'ceil'
)
// change limit direction depending on token direction
?.multipliedBy(buyMode ? -1 : 1)
// change limit direction depending on buying direction
?.multipliedBy(buyMode ? 1 : -1)
: undefined;

const msgPlaceLimitOrder: MsgPlaceLimitOrder = {
Expand Down

0 comments on commit 4872f87

Please sign in to comment.