Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
check buyToken address and set to native
Browse files Browse the repository at this point in the history
  • Loading branch information
W3stside committed Feb 23, 2022
1 parent b542902 commit 4e67235
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/custom/api/gnosisProtocol/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SupportedChainId as ChainId, SupportedChainId } from 'constants/chains'
import { OrderKind, QuoteQuery } from '@gnosis.pm/gp-v2-contracts'
import { stringify } from 'qs'
import { getSigningSchemeApiValue, OrderCancellation, OrderCreation, SigningSchemeValue } from 'utils/signatures'
import { APP_DATA_HASH, GAS_FEE_ENDPOINTS } from 'constants/index'
import { APP_DATA_HASH, GAS_FEE_ENDPOINTS, NATIVE_CURRENCY_BUY_ADDRESS } from 'constants/index'
import { registerOnWindow } from 'utils/misc'
import { isBarn, isDev, isLocal, isPr } from '../../utils/environments'
import OperatorError, {
Expand All @@ -25,6 +25,8 @@ import { ZERO_ADDRESS } from 'constants/misc'
import { getAppDataHash } from 'constants/appDataHash'
import { GpPriceStrategy } from 'hooks/useGetGpPriceStrategy'

import { WETH9_EXTENDED } from 'constants/tokens'

function getGnosisProtocolUrl(): Partial<Record<ChainId, string>> {
if (isLocal || isDev || isPr || isBarn) {
return {
Expand Down Expand Up @@ -337,9 +339,21 @@ function _mapNewToLegacyParams(params: FeeQuoteParams): QuoteQuery {
return finalParams
}

function _returnNativeBuyAddress(address: string, chainId: any) {
if (address.toLowerCase() === WETH9_EXTENDED[chainId].address.toLowerCase()) {
return NATIVE_CURRENCY_BUY_ADDRESS
}

return address
}

export async function getQuote(params: FeeQuoteParams) {
const { chainId } = params
const quoteParams = _mapNewToLegacyParams(params)
const { chainId, buyToken } = params
// we need to check buy/sellToken for native
const checkedBuyToken = _returnNativeBuyAddress(buyToken, chainId)
const extendedParams = { ...params, buyToken: checkedBuyToken }

const quoteParams = _mapNewToLegacyParams(extendedParams)
const response = await _post(chainId, '/quote', quoteParams)

return _handleQuoteResponse<SimpleGetQuoteResponse>(response)
Expand Down

0 comments on commit 4e67235

Please sign in to comment.