Skip to content

Commit

Permalink
Merge pull request #7 from consenlabs/feat-support-fee-engine
Browse files Browse the repository at this point in the history
Feat support fee engine
  • Loading branch information
Xaber20110202 authored Jan 20, 2020
2 parents 648c192 + 0eda292 commit 9870393
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 6 additions & 5 deletions src/router/newOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/router/version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const version = (ctx) => {
ctx.body = {
result: true,
version: '0.3.0',
version: '0.4.0',
}
}
26 changes: 22 additions & 4 deletions src/utils/order.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
Expand Down Expand Up @@ -75,16 +90,19 @@ 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,
feeFactor,
}
}

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 = {
Expand Down

0 comments on commit 9870393

Please sign in to comment.