diff --git a/package.json b/package.json index 2b378f9..9d3cd4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tokenlon-mmsk", - "version": "0.3.0", + "version": "0.4.0", "description": "", "main": "lib/index.js", "types": "src/globals.d.ts", diff --git a/src/router/newOrder.ts b/src/router/newOrder.ts index dbc67d6..506542e 100644 --- a/src/router/newOrder.ts +++ b/src/router/newOrder.ts @@ -37,19 +37,20 @@ export const newOrder = async (ctx) => { } else { const { rate, minAmount, maxAmount, quoteId } = rateBody - const { userAddr } = query + const { userAddr, feefactor } = query const config = updaterStack.markerMakerConfigUpdater.cacheResult const tokenConfigs = updaterStack.tokenConfigsFromImtokenUpdater.cacheResult const tokenList = getSupportedTokens() try { - const orderFormated = getFormatedSignedOrder( - ctx.query, + const orderFormated = getFormatedSignedOrder({ + simpleOrder: ctx.query, rate, - userAddr.toLowerCase(), + userAddr: userAddr.toLowerCase(), tokenList, tokenConfigs, config, - ) + queryFeeFactor: feefactor, + }) ctx.body = { result: true, exchangeable: true, diff --git a/src/router/version.ts b/src/router/version.ts index bb9e923..7224a49 100644 --- a/src/router/version.ts +++ b/src/router/version.ts @@ -1,6 +1,6 @@ export const version = (ctx) => { ctx.body = { result: true, - version: '0.3.0', + version: '0.4.0', } } \ No newline at end of file diff --git a/src/utils/order.ts b/src/utils/order.ts index ca4a840..509b62d 100644 --- a/src/utils/order.ts +++ b/src/utils/order.ts @@ -1,5 +1,6 @@ import { MarketMakerConfig, Token, TokenConfig } from '../types' import { assetDataUtils, generatePseudoRandomSalt, orderHashUtils, signatureUtils, SignerType, SignatureType } from '0x.js' +import * as _ from 'lodash' import * as ethUtils from 'ethereumjs-util' import { toBN } from './math' import { getTokenBySymbol } from './token' @@ -14,7 +15,21 @@ const getFixPrecision = (decimal) => { return decimal < 8 ? decimal : 9 } -const getOrderAndFeeFactor = (simpleOrder, rate, tokenList: Token[], tokenConfigs: TokenConfig[], config: MarketMakerConfig) => { +interface GetOrderAndFeeFactorParams { + simpleOrder: any + rate: number | string + tokenList: Token[] + tokenConfigs: TokenConfig[] + config: MarketMakerConfig + queryFeeFactor?: number +} + +interface GetFormatedSignedOrderParams extends GetOrderAndFeeFactorParams { + userAddr: string +} + +const getOrderAndFeeFactor = (params: GetOrderAndFeeFactorParams) => { + const {simpleOrder, rate, tokenList, tokenConfigs, config, queryFeeFactor } = params const { side, amount } = simpleOrder const baseToken = getTokenBySymbol(tokenList, simpleOrder.base) const quoteToken = getTokenBySymbol(tokenList, simpleOrder.quote) @@ -75,7 +90,9 @@ const getOrderAndFeeFactor = (simpleOrder, rate, tokenList: Token[], tokenConfig } const foundTokenConfig = tokenConfigs.find(t => t.symbol === takerToken.symbol) - const feeFactor = foundTokenConfig && foundTokenConfig.feeFactor ? foundTokenConfig.feeFactor : (config.feeFactor ? config.feeFactor : 0) + const feeFactor = !_.isUndefined(queryFeeFactor) && !_.isNaN(+queryFeeFactor) && +queryFeeFactor >= 0 ? +queryFeeFactor : ( + foundTokenConfig && foundTokenConfig.feeFactor ? foundTokenConfig.feeFactor : (config.feeFactor ? config.feeFactor : 0) + ) return { order, @@ -83,8 +100,9 @@ const getOrderAndFeeFactor = (simpleOrder, rate, tokenList: Token[], tokenConfig } } -export const getFormatedSignedOrder = (simpleOrder, rate, userAddr, tokenList: Token[], tokenConfigs: TokenConfig[], config: MarketMakerConfig) => { - const { order, feeFactor } = getOrderAndFeeFactor(simpleOrder, rate, tokenList, tokenConfigs, config) +export const getFormatedSignedOrder = (params: GetFormatedSignedOrderParams) => { + const { userAddr } = params + const { order, feeFactor } = getOrderAndFeeFactor(params) const wallet = getWallet() const o = {