diff --git a/ts/client/src/market.ts b/ts/client/src/market.ts index d9ea16d85..af60f77b7 100644 --- a/ts/client/src/market.ts +++ b/ts/client/src/market.ts @@ -5,20 +5,15 @@ import { type Message, } from '@solana/web3.js'; import { - type MarketAccount, OPENBOOK_PROGRAM_ID, getFilteredProgramAccounts, - nameToString, } from './client'; import { utils, Program, type Provider, getProvider, - BN, } from '@coral-xyz/anchor'; -import { toNative, toUiDecimals } from './utils/utils'; -import Big from 'big.js'; import { IDL, type OpenbookV2 } from './openbook_v2'; const BATCH_TX_SIZE = 50; @@ -121,65 +116,4 @@ export async function findAllMarkets( } } return marketsAll; -} - -function priceLotsToUiConverter(market: MarketAccount): number { - return new Big(10) - .pow(market.baseDecimals - market.quoteDecimals) - .mul(new Big(market.quoteLotSize.toString())) - .div(new Big(market.baseLotSize.toString())) - .toNumber(); -} - -function baseLotsToUiConverter(market: MarketAccount): number { - return new Big(market.baseLotSize.toString()) - .div(new Big(10).pow(market.baseDecimals)) - .toNumber(); -} -function quoteLotsToUiConverter(market: MarketAccount): number { - return new Big(market.quoteLotSize.toString()) - .div(new Big(10).pow(market.quoteDecimals)) - .toNumber(); -} - -export function uiPriceToLots(market: MarketAccount, price: number): BN { - return toNative(price, market.quoteDecimals) - .mul(market.baseLotSize) - .div(market.quoteLotSize.mul(new BN(Math.pow(10, market.baseDecimals)))); -} - -export function uiBaseToLots(market: MarketAccount, quantity: number): BN { - return toNative(quantity, market.baseDecimals).div(market.baseLotSize); -} - -export function uiQuoteToLots(market: MarketAccount, uiQuote: number): BN { - return toNative(uiQuote, market.quoteDecimals).div(market.quoteLotSize); -} - -export function priceLotsToNative(market: MarketAccount, price: BN): BN { - return price.mul(market.quoteLotSize).div(market.baseLotSize); -} - -export function priceLotsToUi(market: MarketAccount, price: BN): number { - return parseFloat(price.toString()) * priceLotsToUiConverter(market); -} - -export function priceNativeToUi(market: MarketAccount, price: number): number { - return toUiDecimals(price, market.quoteDecimals - market.baseDecimals); -} - -export function baseLotsToUi(market: MarketAccount, quantity: BN): number { - return parseFloat(quantity.toString()) * baseLotsToUiConverter(market); -} - -export function quoteLotsToUi(market: MarketAccount, quantity: BN): number { - return parseFloat(quantity.toString()) * quoteLotsToUiConverter(market); -} - -export function quantityToUiBase( - market: MarketAccount, - quantity: BN, - decimals: number, -): number { - return toUiDecimals(quantity.mul(market.baseLotSize).toNumber(), decimals); -} +} \ No newline at end of file