From 5ec33190b7e547b7388978d870df311f63aec8ce Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 12 Dec 2024 20:47:19 +0300 Subject: [PATCH] fix requested changes --- src/dex/cables/cables.ts | 85 ++++++++-------------------------- src/dex/cables/rate-fetcher.ts | 7 --- src/dex/cables/types.ts | 27 ++--------- 3 files changed, 24 insertions(+), 95 deletions(-) diff --git a/src/dex/cables/cables.ts b/src/dex/cables/cables.ts index 583dcd8b5..e8272350f 100644 --- a/src/dex/cables/cables.ts +++ b/src/dex/cables/cables.ts @@ -56,6 +56,7 @@ import BigNumber from 'bignumber.js'; import { ethers } from 'ethers'; import { BI_MAX_UINT256 } from '../../bigint-constants'; import _ from 'lodash'; +import { BebopData } from '../bebop/types'; export class Cables extends SimpleExchange implements IDex { public static dexKeysWithNetwork: { key: string; networks: Network[] }[] = @@ -116,10 +117,6 @@ export class Cables extends SimpleExchange implements IDex { blacklistIntervalMs: CABLES_API_BLACKLIST_POLLING_INTERVAL_MS, blacklistCacheTTLSecs: CABLES_BLACKLIST_CACHES_TTL_S, blacklistCacheKey: CABLES_BLACKLIST_CACHE_KEY, - - tokensHandleResponseCallback: async () => { - await this.setTokensMap(); - }, }, }, ); @@ -255,6 +252,21 @@ export class Cables extends SimpleExchange implements IDex { } } + getAdapterParam( + srcToken: string, + destToken: string, + srcAmount: string, + destAmount: string, + data: BebopData, + side: SwapSide, + ): AdapterExchangeParam { + return { + targetExchange: this.mainnetRFQAddress, + payload: '0x', + networkFee: '0', + }; + } + getDexParam( srcToken: Address, destToken: Address, @@ -315,64 +327,6 @@ export class Cables extends SimpleExchange implements IDex { }; } - getAdapterParam( - srcToken: string, - destToken: string, - srcAmount: string, - destAmount: string, - data: CablesData, - side: SwapSide, - ): AdapterExchangeParam { - const { quoteData } = data; - - assert( - quoteData !== undefined, - `${this.dexKey}-${this.network}: quoteData undefined`, - ); - - const params = [ - { - nonceAndMeta: quoteData.nonceAndMeta, - expiry: quoteData.expiry, - makerAsset: quoteData.makerAsset, - takerAsset: quoteData.takerAsset, - maker: quoteData.maker, - taker: quoteData.taker, - makerAmount: quoteData.makerAmount, - takerAmount: quoteData.takerAmount, - }, - quoteData.signature, - ]; - - const payload = this.abiCoder.encodeParameter( - { - ParentStruct: { - order: { - nonceAndMeta: 'uint256', - expiry: 'uint128', - makerAsset: 'address', - takerAsset: 'address', - maker: 'address', - taker: 'address', - makerAmount: 'uint256', - takerAmount: 'uint256', - }, - signature: 'bytes', - }, - }, - { - order: params[0], - signature: params[1], - }, - ); - - return { - targetExchange: this.mainnetRFQAddress, - payload, - networkFee: '0', - }; - } - normalizeToken(token: Token): Token { return { ...token, @@ -398,8 +352,6 @@ export class Cables extends SimpleExchange implements IDex { side: SwapSide, blockNumber: number, ): Promise { - await this.setTokensMap(); - if (!srcToken || !destToken) { return []; } @@ -414,6 +366,7 @@ export class Cables extends SimpleExchange implements IDex { return []; } + await this.setTokensMap(); const tokensAddr = (await this.getCachedTokensAddr()) || {}; return [ @@ -662,7 +615,7 @@ export class Cables extends SimpleExchange implements IDex { } releaseResources?(): AsyncOrSync { - if (this.rateFetcher) { + if (!this.dexHelper.config.isSlave && this.rateFetcher) { this.rateFetcher.stop(); } } @@ -919,7 +872,7 @@ export class Cables extends SimpleExchange implements IDex { const cachedBlacklist = await this.dexHelper.cache.get( this.dexKey, this.network, - CABLES_BLACKLIST_CACHE_KEY, + this.rateFetcher.blacklistCacheKey, ); if (cachedBlacklist) { diff --git a/src/dex/cables/rate-fetcher.ts b/src/dex/cables/rate-fetcher.ts index 463277f23..3df0b0f83 100644 --- a/src/dex/cables/rate-fetcher.ts +++ b/src/dex/cables/rate-fetcher.ts @@ -35,8 +35,6 @@ export class CablesRateFetcher { public blacklistCacheKey: string; public blacklistCacheTTL: number; - tokensHandleResponseCallback: () => Promise; - constructor( private dexHelper: IDexHelper, private dexKey: string, @@ -56,9 +54,6 @@ export class CablesRateFetcher { this.blacklistCacheKey = config.rateConfig.blacklistCacheKey; this.blacklistCacheTTL = config.rateConfig.blacklistCacheTTLSecs; - this.tokensHandleResponseCallback = - config.rateConfig.tokensHandleResponseCallback; - this.pairsFetcher = new Fetcher( dexHelper.httpRequest, { @@ -213,7 +208,5 @@ export class CablesRateFetcher { this.tokensCacheTTL, JSON.stringify(normalizedTokens), ); - - await this.tokensHandleResponseCallback(); } } diff --git a/src/dex/cables/types.ts b/src/dex/cables/types.ts index 7017e70e6..b8f5d14de 100644 --- a/src/dex/cables/types.ts +++ b/src/dex/cables/types.ts @@ -11,21 +11,6 @@ export type CablesRFQResponse = { export type CablesData = { quoteData?: AugustusRFQOrderData; }; - -export enum OrderbookSide { - bids = 'bids', - asks = 'asks', -} - -/** - * Utils - */ -export type CablesAPIParameters = { - url: string; - method: Method; -}; -export class CablesRfqError extends Error {} - /** * Types */ @@ -35,26 +20,26 @@ export type PairData = { liquidityUSD: number; }; -export type PriceAndAmount = [string, string]; +type PriceAndAmount = [string, string]; -export type PriceData = { +type PriceData = { bids: PriceAndAmount[]; asks: PriceAndAmount[]; }; -export type PriceDataMap = { +type PriceDataMap = { [network: string]: { [pair: string]: PriceData; }; }; -export type TokenDataMap = { +type TokenDataMap = { [network: string]: { [token: string]: Token; }; }; -export type PairsDataMap = { +type PairsDataMap = { [network: string]: { [token: string]: PairData; }; @@ -115,8 +100,6 @@ export type CablesRateFetcherConfig = { pairsCacheTTLSecs: number; pricesCacheTTLSecs: number; tokensCacheTTLSecs: number; - - tokensHandleResponseCallback: () => Promise; }; };