diff --git a/src/dex/dexalot/constants.ts b/src/dex/dexalot/constants.ts index e46d3b0fb..b7f385620 100644 --- a/src/dex/dexalot/constants.ts +++ b/src/dex/dexalot/constants.ts @@ -10,8 +10,6 @@ export const DEXALOT_API_PRICES_POLLING_INTERVAL_MS = 1000; export const DEXALOT_API_PAIRS_POLLING_INTERVAL_MS = 1000 * 60 * 10; // 10 mins -export const DEXALOT_API_TOKENS_POLLING_INTERVAL_MS = 1000 * 60 * 10; // 10 mins - export const DEXALOT_API_BLACKLIST_POLLING_INTERVAL_MS = 1000 * 60 * 60; // 1 hour export const DEXALOT_API_URL = 'https://api.dexalot.com'; diff --git a/src/dex/dexalot/dexalot.ts b/src/dex/dexalot/dexalot.ts index 1d7d6aa7c..1db04599d 100644 --- a/src/dex/dexalot/dexalot.ts +++ b/src/dex/dexalot/dexalot.ts @@ -47,13 +47,11 @@ import { DEXALOT_GAS_COST, DEXALOT_PAIRS_CACHES_TTL_S, DEXALOT_API_PAIRS_POLLING_INTERVAL_MS, - DEXALOT_API_TOKENS_POLLING_INTERVAL_MS, DEXALOT_TOKENS_CACHES_TTL_S, DEXALOT_API_BLACKLIST_POLLING_INTERVAL_MS, DEXALOT_RATE_LIMITED_TTL_S, } from './constants'; import { BI_MAX_UINT256 } from '../../bigint-constants'; -import { TooStrictSlippageCheckError } from '../generic-rfq/types'; import { ethers } from 'ethers'; import BigNumber from 'bignumber.js'; @@ -111,24 +109,23 @@ export class Dexalot extends SimpleExchange implements IDex { rateConfig: { pairsIntervalMs: DEXALOT_API_PAIRS_POLLING_INTERVAL_MS, pricesIntervalMs: DEXALOT_API_PRICES_POLLING_INTERVAL_MS, - tokensIntervalMs: DEXALOT_API_TOKENS_POLLING_INTERVAL_MS, blacklistIntervalMs: DEXALOT_API_BLACKLIST_POLLING_INTERVAL_MS, pairsReqParams: { url: `${DEXALOT_API_URL}/api/rfq/pairs`, headers: { 'x-apikey': this.dexalotAuthToken, }, + params: { + chainid: this.network, + }, }, pricesReqParams: { url: `${DEXALOT_API_URL}/api/rfq/prices`, headers: { 'x-apikey': this.dexalotAuthToken, }, - }, - tokensReqParams: { - url: `${DEXALOT_API_URL}/api/rfq/tokens`, - headers: { - 'x-apikey': this.dexalotAuthToken, + params: { + chainid: this.network, }, }, blacklistReqParams: { @@ -504,6 +501,7 @@ export class Dexalot extends SimpleExchange implements IDex { takerAmount: side === SwapSide.SELL ? optimalSwapExchange.srcAmount : undefined, userAddress: options.txOrigin, + chainid: this.network, }; const rfq: RFQResponse = await this.dexHelper.httpRequest.post( @@ -517,9 +515,10 @@ export class Dexalot extends SimpleExchange implements IDex { 'Missing quote data', `RFQ ${swapIdentifier} ${JSON.stringify(rfq)}`, ); - } else if (!rfq.order.signature) { + } else if (!rfq.signature) { this.generateRFQError('Missing signature', swapIdentifier); } + rfq.order.signature = rfq.signature; const { order } = rfq; diff --git a/src/dex/dexalot/rate-fetcher.ts b/src/dex/dexalot/rate-fetcher.ts index 5b1cbf75c..5cba7f322 100644 --- a/src/dex/dexalot/rate-fetcher.ts +++ b/src/dex/dexalot/rate-fetcher.ts @@ -8,13 +8,11 @@ import { PairDataMap, DexalotPricesResponse, PriceDataMap, - DexalotTokensResponse, DexalotBlacklistResponse, } from './types'; import { pricesResponseValidator, pairsResponseValidator, - tokensResponseValidator, blacklistResponseValidator, } from './validators'; import { Network } from '../../constants'; @@ -28,7 +26,6 @@ export class RateFetcher { private pricesCacheKey: string; private pricesCacheTTL: number; - private tokensFetcher: Fetcher; private tokensAddrCacheKey: string; private tokensCacheKey: string; private tokensCacheTTL: number; @@ -88,24 +85,6 @@ export class RateFetcher { logger, ); - this.tokensFetcher = new Fetcher( - dexHelper.httpRequest, - { - info: { - requestOptions: config.rateConfig.tokensReqParams, - caster: (data: unknown) => { - return validateAndCast( - data, - tokensResponseValidator, - ); - }, - }, - handler: this.handleTokensResponse.bind(this), - }, - config.rateConfig.tokensIntervalMs, - logger, - ); - this.blacklistFetcher = new Fetcher( dexHelper.httpRequest, { @@ -128,22 +107,36 @@ export class RateFetcher { start() { this.pairsFetcher.startPolling(); this.rateFetcher.startPolling(); - this.tokensFetcher.startPolling(); this.blacklistFetcher.startPolling(); } stop() { this.pairsFetcher.stopPolling(); this.rateFetcher.stopPolling(); - this.tokensFetcher.stopPolling(); this.blacklistFetcher.stopPolling(); } private handlePairsResponse(resp: DexalotPairsResponse): void { - const { pairs } = resp; + const pairs = resp; const dexPairs: PairDataMap = {}; + const tokenMap: { [address: string]: Token } = {}; + const tokenAddrMap: { [symbol: string]: string } = {}; Object.keys(pairs).forEach(pair => { dexPairs[pair.toLowerCase()] = pairs[pair]; + tokenAddrMap[pairs[pair].base.toLowerCase()] = + pairs[pair].baseAddress.toLowerCase(); + tokenAddrMap[pairs[pair].quote.toLowerCase()] = + pairs[pair].quoteAddress.toLowerCase(); + tokenMap[pairs[pair].baseAddress.toLowerCase()] = { + address: pairs[pair].baseAddress.toLowerCase(), + symbol: pairs[pair].base, + decimals: pairs[pair].baseDecimals, + }; + tokenMap[pairs[pair].quoteAddress.toLowerCase()] = { + address: pairs[pair].quoteAddress.toLowerCase(), + symbol: pairs[pair].quote, + decimals: pairs[pair].quoteDecimals, + }; }); this.dexHelper.cache.setex( this.dexKey, @@ -152,6 +145,20 @@ export class RateFetcher { this.pairsCacheTTL, JSON.stringify(dexPairs), ); + this.dexHelper.cache.setex( + this.dexKey, + this.network, + this.tokensCacheKey, + this.tokensCacheTTL, + JSON.stringify(tokenMap), + ); + this.dexHelper.cache.setex( + this.dexKey, + this.network, + this.tokensAddrCacheKey, + this.tokensCacheTTL, + JSON.stringify(tokenAddrMap), + ); } private handleRatesResponse(resp: DexalotPricesResponse): void { @@ -169,35 +176,6 @@ export class RateFetcher { ); } - private handleTokensResponse(resp: DexalotTokensResponse): void { - const { tokens } = resp; - const tokenMap: { [address: string]: Token } = {}; - const tokenAddrMap: { [pair: string]: string } = {}; - Object.keys(tokens).forEach(symbol => { - const token = tokens[symbol]; - tokenMap[token.address.toLowerCase()] = { - address: token.address.toLowerCase(), - symbol: token.symbol, - decimals: token.decimals, - }; - tokenAddrMap[token.symbol.toLowerCase()] = token.address.toLowerCase(); - }); - this.dexHelper.cache.setex( - this.dexKey, - this.network, - this.tokensCacheKey, - this.tokensCacheTTL, - JSON.stringify(tokenMap), - ); - this.dexHelper.cache.setex( - this.dexKey, - this.network, - this.tokensAddrCacheKey, - this.tokensCacheTTL, - JSON.stringify(tokenAddrMap), - ); - } - private async handleBlacklistResponse( resp: DexalotBlacklistResponse, ): Promise { diff --git a/src/dex/dexalot/types.ts b/src/dex/dexalot/types.ts index fba44c1cd..841fcddf6 100644 --- a/src/dex/dexalot/types.ts +++ b/src/dex/dexalot/types.ts @@ -10,11 +10,12 @@ type RFQOrder = { taker: string; makerAmount: string; takerAmount: string; - signature: string; + signature?: string; }; export type RFQResponse = { order: RFQOrder; + signature: string; }; export type RFQResponseError = { @@ -52,8 +53,18 @@ export type PairDataMap = { [pair: string]: PairData; }; +export type PairDataResp = { + base: string; + quote: string; + liquidityUSD: number; + baseAddress: string; + quoteAddress: string; + baseDecimals: number; + quoteDecimals: number; +}; + export type DexalotPairsResponse = { - pairs: PairDataMap; + [pair: string]: PairDataResp; }; type PriceData = { @@ -73,25 +84,10 @@ export type TokenAddrDataMap = { [symbol: string]: string; }; -type TokenData = { - symbol: string; - name: string; - description: string; - address: any; - decimals: number; - type: string; -}; - export type TokenDataMap = { [address: string]: Token; }; -export type DexalotTokensResponse = { - tokens: { - [token: string]: TokenData; - }; -}; - export type DexalotBlacklistResponse = { blacklist: string[]; }; @@ -108,11 +104,6 @@ export type DexalotRateFetcherConfig = { headers?: RequestHeaders; params?: any; }; - tokensReqParams: { - url: string; - headers?: RequestHeaders; - params?: any; - }; blacklistReqParams: { url: string; headers?: RequestHeaders; @@ -120,7 +111,6 @@ export type DexalotRateFetcherConfig = { }; pairsIntervalMs: number; pricesIntervalMs: number; - tokensIntervalMs: number; blacklistIntervalMs: number; pairsCacheKey: string; pricesCacheKey: string; diff --git a/src/dex/dexalot/validators.ts b/src/dex/dexalot/validators.ts index 52ca64a57..89a2e11e1 100644 --- a/src/dex/dexalot/validators.ts +++ b/src/dex/dexalot/validators.ts @@ -4,17 +4,20 @@ const pairValidator = joi.object({ base: joi.string().min(1).required(), quote: joi.string().min(1).required(), liquidityUSD: joi.number().min(0).required(), + baseAddress: joi.string().min(1).required(), + quoteAddress: joi.string().min(1).required(), + baseDecimals: joi.number().min(0).required(), + quoteDecimals: joi.number().min(0).required(), }); -export const pairsResponseValidator = joi.object({ - pairs: joi.object().pattern(joi.string(), pairValidator), -}); +export const pairsResponseValidator = joi + .object() + .pattern(joi.string(), pairValidator); const orderbookRecordValidator = joi .array() .items(joi.string().min(1)) - .length(2) - .required(); + .length(2); const orderbookValidator = joi.object({ bids: joi.array().items(orderbookRecordValidator).required(),