Skip to content

Commit

Permalink
Merge pull request #64 from consenlabs/feature/fix_oom
Browse files Browse the repository at this point in the history
fix oom
  • Loading branch information
fengweiqiang-coder authored Sep 20, 2023
2 parents 2d1a1b7 + 70bafb9 commit 2b95c09
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
18 changes: 12 additions & 6 deletions src/handler/newOrder.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -223,10 +223,10 @@ export const newOrder = async (ctx): Promise<Response> => {
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,
Expand All @@ -237,7 +237,10 @@ export const newOrder = async (ctx): Promise<Response> => {
// 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
}
Expand All @@ -246,7 +249,10 @@ export const newOrder = async (ctx): Promise<Response> => {
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
}
Expand Down
12 changes: 6 additions & 6 deletions src/utils/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit 2b95c09

Please sign in to comment.