From 1bec33bfb70ed6b206e0aec37be407007ffbf859 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Sat, 30 Sep 2023 01:07:50 +0300 Subject: [PATCH] refactor --- src/dex/dexalot/dexalot.ts | 40 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/dex/dexalot/dexalot.ts b/src/dex/dexalot/dexalot.ts index 7eee6b0a6..99880a9e2 100644 --- a/src/dex/dexalot/dexalot.ts +++ b/src/dex/dexalot/dexalot.ts @@ -59,6 +59,8 @@ import { import { BI_MAX_UINT256 } from '../../bigint-constants'; import { ethers } from 'ethers'; import BigNumber from 'bignumber.js'; +import { Method } from '../../dex-helper/irequest-wrapper'; +import { SwaapV2APIParameters } from '../swaap-v2/types'; export class Dexalot extends SimpleExchange implements IDex { readonly isStatePollingDex = true; @@ -116,30 +118,9 @@ export class Dexalot extends SimpleExchange implements IDex { pairsIntervalMs: DEXALOT_API_PAIRS_POLLING_INTERVAL_MS, pricesIntervalMs: DEXALOT_API_PRICES_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, - }, - params: { - chainid: this.network, - }, - }, - blacklistReqParams: { - url: `${DEXALOT_API_URL}/api/rfq/blacklist`, - headers: { - 'x-apikey': this.dexalotAuthToken, - }, - }, + pairsReqParams: this.getAPIReqParams('api/rfq/pairs', 'GET'), + pricesReqParams: this.getAPIReqParams('api/rfq/prices', 'GET'), + blacklistReqParams: this.getAPIReqParams('api/rfq/blacklist', 'GET'), pairsCacheKey: this.pairsCacheKey, pairsCacheTTLSecs: DEXALOT_PAIRS_CACHES_TTL_S, pricesCacheKey: this.pricesCacheKey, @@ -917,6 +898,17 @@ export class Dexalot extends SimpleExchange implements IDex { return pairsByLiquidity.slice(0, limit); } + getAPIReqParams(endpoint: string, method: Method): SwaapV2APIParameters { + return { + url: `${DEXALOT_API_URL}/${endpoint}`, + headers: { 'x-apikey': this.dexalotAuthToken }, + params: { + chainid: this.network, + }, + method: method, + }; + } + releaseResources(): void { if (this.rateFetcher) { this.rateFetcher.stop();