From 70bafb9129a045d2af05e0ec53cc7f4a70971738 Mon Sep 17 00:00:00 2001 From: fengweiqiang-coder Date: Wed, 20 Sep 2023 11:16:49 +0800 Subject: [PATCH] fix oom --- src/handler/newOrder.ts | 18 ++++++++++++------ src/utils/token.ts | 12 ++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/handler/newOrder.ts b/src/handler/newOrder.ts index 257d2e8..7f2f9bd 100644 --- a/src/handler/newOrder.ts +++ b/src/handler/newOrder.ts @@ -1,7 +1,7 @@ import { memoize } from 'lodash' import { Quoter } from '../request/marketMaker' import { updaterStack } from '../worker' -import { Protocol, QueryInterface } from '../types' +import { Protocol, QueryInterface, Token } from '../types' import { validateNewOrderRequest, validateRequest } from '../validations' import { ValidationError } from './errors' import { addQuoteIdPrefix, constructQuoteResponse, preprocessQuote } from '../quoting' @@ -223,10 +223,10 @@ export const newOrder = async (ctx): Promise => { const rateBody = await requestMarketMaker(quoter, query) const config = updaterStack.markerMakerConfigUpdater.cacheResult const tokenConfigs = updaterStack.tokenConfigsFromImtokenUpdater.cacheResult - const tokenList = getSupportedTokens() - + const tokensWithoutMinMaxAmount = getSupportedTokens() + const tokensWithMinMaxAmount: Token[] = updaterStack.tokenListFromImtokenUpdater.cacheResult const { rate, minAmount, maxAmount, quoteId, salt } = rateBody - const order = getOrderAndFeeFactor(query, rate, tokenList, tokenConfigs, config) + const order = getOrderAndFeeFactor(query, rate, tokensWithoutMinMaxAmount, tokenConfigs, config) const resp: Response = { rate, minAmount, @@ -237,7 +237,10 @@ export const newOrder = async (ctx): Promise => { // directly use system token config { const baseTokenAddr = query.baseAddress - const baseToken = getBaseTokenByAddress(baseTokenAddr.toLowerCase(), tokenList) + const baseToken = getBaseTokenByAddress( + baseTokenAddr.toLowerCase(), + tokensWithMinMaxAmount + ) resp.minAmount = baseToken.minTradeAmount resp.maxAmount = baseToken.maxTradeAmount } @@ -246,7 +249,10 @@ export const newOrder = async (ctx): Promise => { case Protocol.AMMV2: { const baseTokenAddr = query.baseAddress - const baseToken = getBaseTokenByAddress(baseTokenAddr.toLowerCase(), tokenList) + const baseToken = getBaseTokenByAddress( + baseTokenAddr.toLowerCase(), + tokensWithMinMaxAmount + ) resp.minAmount = baseToken.minTradeAmount resp.maxAmount = baseToken.maxTradeAmount } diff --git a/src/utils/token.ts b/src/utils/token.ts index 6ca0940..2a05bf6 100644 --- a/src/utils/token.ts +++ b/src/utils/token.ts @@ -79,14 +79,14 @@ export const getSupportedTokens = (): SupportedToken[] => { pairsFromMMUpdater.cacheResult ) const tokenList: Token[] = tokenListFromImtokenUpdater.cacheResult + const tokensWithoutMinMaxAmount = tokenList.map( + ({ minTradeAmount, maxTradeAmount, ...rest }) => rest + ) const lists = { - tokenList: tokenList, - tokenStack: tokenStack + tokenList: tokensWithoutMinMaxAmount, + tokenStack: tokenStack, } - return mapTokens( - JSON.stringify(lists), - lists - ) + return mapTokens(JSON.stringify(lists), lists) } export const isSupportedBaseQuote = (