Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
fix: handle addresses in depth
Browse files Browse the repository at this point in the history
  • Loading branch information
dekz committed Aug 8, 2020
1 parent 2866253 commit dbbb3d8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/handlers/swap_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as HttpStatus from 'http-status-codes';
import { CHAIN_ID, RFQT_API_KEY_WHITELIST } from '../config';
import {
DEFAULT_QUOTE_SLIPPAGE_PERCENTAGE,
DEFAULT_TOKEN_DECIMALS,
MARKET_DEPTH_DEFAULT_DISTRIBUTION,
MARKET_DEPTH_MAX_SAMPLES,
SWAP_DOCS_URL,
Expand Down Expand Up @@ -133,8 +134,25 @@ export class SwapHandlers {
}

public async getMarketDepthAsync(req: express.Request, res: express.Response): Promise<void> {
const makerToken = getTokenMetadataIfExists(req.query.buyToken as string, CHAIN_ID);
const takerToken = getTokenMetadataIfExists(req.query.sellToken as string, CHAIN_ID);
const makerToken = {
decimals: DEFAULT_TOKEN_DECIMALS,
tokenAddress: req.query.buyToken,
...getTokenMetadataIfExists(req.query.buyToken as string, CHAIN_ID),
};
const takerToken = {
decimals: DEFAULT_TOKEN_DECIMALS,
tokenAddress: req.query.sellToken,
...getTokenMetadataIfExists(req.query.sellToken as string, CHAIN_ID),
};
if (makerToken.tokenAddress === takerToken.tokenAddress) {
throw new ValidationError([
{
field: 'buyToken',
code: ValidationErrorCodes.InvalidAddress,
reason: `Invalid pair ${takerToken.tokenAddress}/${makerToken.tokenAddress}`,
},
]);
}
const response = await this._swapService.calculateMarketDepthAsync({
buyToken: makerToken,
sellToken: takerToken,
Expand Down

0 comments on commit dbbb3d8

Please sign in to comment.