diff --git a/src/connectors/kujira/kujira.convertors.ts b/src/connectors/kujira/kujira.convertors.ts index 188157c632..151d220922 100644 --- a/src/connectors/kujira/kujira.convertors.ts +++ b/src/connectors/kujira/kujira.convertors.ts @@ -489,6 +489,7 @@ export const convertKujiraBalancesToBalances = async ( unsettled: BigNumber(0), total: BigNumber(0), inUSD: { + quotation: BigNumber(0), free: BigNumber(0), lockedInOrders: BigNumber(0), unsettled: BigNumber(0), @@ -500,6 +501,7 @@ export const convertKujiraBalancesToBalances = async ( output.tokens.get(token.id) ); tokenBalance.free = freeAmount; + tokenBalance.inUSD.quotation = quotation; tokenBalance.inUSD.free = freeAmount.multipliedBy(quotation); } } @@ -522,6 +524,7 @@ export const convertKujiraBalancesToBalances = async ( unsettled: BigNumber(0), total: BigNumber(0), inUSD: { + quotation: BigNumber(0), free: BigNumber(0), lockedInOrders: BigNumber(0), unsettled: BigNumber(0), @@ -535,6 +538,8 @@ export const convertKujiraBalancesToBalances = async ( const amount = order.amount; + tokenBalance.inUSD.quotation = quotation; + if ([OrderStatus.OPEN, OrderStatus.PARTIALLY_FILLED].includes( getNotNullOrThrowError(order.status) )) { diff --git a/src/connectors/kujira/kujira.helpers.ts b/src/connectors/kujira/kujira.helpers.ts index 9572e51878..094d77371d 100644 --- a/src/connectors/kujira/kujira.helpers.ts +++ b/src/connectors/kujira/kujira.helpers.ts @@ -4,21 +4,6 @@ import { KujiraConfig } from './kujira.config'; import { Kujira } from './kujira'; import { parse as flattedParse, stringify as flattedStringify } from 'flatted'; import { promisify } from 'util'; -import { - GetAllTickersResponse, - IMap, - MarketId, - MarketName, - Token, - Ticker, - Price, - TokenId, - TokenName, - TokenPriceInDolar, -} from './kujira.types'; -import { BigNumber } from 'bignumber.js'; -import { axlUSDC } from 'kujira.js'; -import { convertKujiraTokenToToken } from './kujira.convertors'; /** * @@ -218,139 +203,3 @@ export namespace Serializer { return deserialize(deserializedString) as T; } } - -export const quoteABaseTokenInDolars = async ( - chain: string, - network: string, - targetToken: TokenName, - allTickers?: GetAllTickersResponse -): Promise => { - if (targetToken.toUpperCase() == 'USDC') { - return { - token: targetToken, - price: BigNumber(1), - } as TokenPriceInDolar; - } - - if (!allTickers) { - const connector = getNotNullOrThrowError( - Kujira.getInstance(chain, network) - ); - - allTickers = await connector.getAllTickers({}); - } - - const usdcAsQuote: IMap = getNotNullOrThrowError< - IMap - >( - allTickers - ?.valueSeq() - .toArray() - .filter( - (ticker) => ticker.market.quoteToken.symbol.toUpperCase() == 'USDC' - ) - ); - - const priceSource = usdcAsQuote.filter( - (ticker) => - ticker.market.baseToken.symbol.toUpperCase() == targetToken.toUpperCase() - ); - - const targetTokenAsQuote: IMap = - getNotNullOrThrowError( - allTickers - ?.valueSeq() - .toArray() - .filter( - (ticker) => - ticker.market.quoteToken.symbol.toUpperCase() == - targetToken.toUpperCase() - ) - ); - - if (priceSource.size > 0) { - return { - token: getNotNullOrThrowError(priceSource.valueSeq().first()) - .market.name, - price: getNotNullOrThrowError(priceSource.valueSeq().first()) - .price, - } as TokenPriceInDolar; - } else { - // const pricesIntersection = usdcAsQuote.filter( - // ticker => ticker.market.baseToken.symbol.toUpperCase() == ( - // getNotNullOrThrowError( - // tokenAsQuote.filter( - // value => value.market.baseToken.symbol.toUpperCase() == ticker.market.baseToken.symbol.toUpperCase() - // && value.market.quoteToken.symbol.toUpperCase() == targetToken.toUpperCase() - // ) - // ) - // ) - // ) as IMap; - - const reference = {} as TokenPriceInDolar; - - for (const aTicker of usdcAsQuote.valueSeq().toArray()) { - for (const bTicker of targetTokenAsQuote.valueSeq().toArray()) { - if ( - aTicker.market.baseToken.symbol == bTicker.market.baseToken.symbol && - bTicker.market.quoteToken.symbol.toUpperCase() == - targetToken.toUpperCase() - ) { - reference.token = aTicker.market.baseToken.symbol; - reference.price = aTicker.price; - } - } - } - - return reference; - } -}; - -export const getQuotationInUSD = ( - token: Token, - tickers: IMap -): { price: Price } => { - const quoteToken = convertKujiraTokenToToken(axlUSDC); - - const tickerValues = tickers - .valueSeq() - .filter( - (ticker) => - ticker.market.baseToken.id == token.id && - ticker.market.quoteToken.id == quoteToken.id - ) - .first(); - - const ticker = - tickerValues != undefined - ? tickerValues - : tickers - .valueSeq() - .filter( - (ticker) => - ticker.market.quoteToken.id == token.id && - ticker.market.baseToken.id == quoteToken.id - ) - .first(); - - let buySide = false; - - if ( - getNotNullOrThrowError( - ticker?.market.quoteToken.symbol != quoteToken.symbol - ) - ) { - buySide = true; - } - let price = - token.id == quoteToken.id ? BigNumber(1) : ticker?.price || BigNumber(0); - - if (buySide) { - const difference = BigNumber(1).minus(price); - price = BigNumber(1).plus(difference); - } - - return { - price: price, - }; -}; diff --git a/src/connectors/kujira/kujira.types.ts b/src/connectors/kujira/kujira.types.ts index 974502ecae..4edf82b8fe 100644 --- a/src/connectors/kujira/kujira.types.ts +++ b/src/connectors/kujira/kujira.types.ts @@ -252,12 +252,16 @@ export interface SimplifiedBalance { total: Amount; } +export interface SimplifiedBalanceWithUSD extends SimplifiedBalance { + quotation: Amount; +} + // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface TotalBalance extends SimplifiedBalance {} export interface TokenBalance extends SimplifiedBalance { token: Token; - inUSD: SimplifiedBalance; + inUSD: SimplifiedBalanceWithUSD; } export interface Balances {