Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mschneider committed Apr 15, 2024
1 parent e050696 commit 950709f
Showing 1 changed file with 1 addition and 67 deletions.
68 changes: 1 addition & 67 deletions ts/client/src/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 950709f

Please sign in to comment.