Skip to content

Commit

Permalink
fix requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Dec 12, 2024
1 parent 428ccfc commit 5ec3319
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 95 deletions.
85 changes: 19 additions & 66 deletions src/dex/cables/cables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
Expand Down Expand Up @@ -116,10 +117,6 @@ export class Cables extends SimpleExchange implements IDex<any> {
blacklistIntervalMs: CABLES_API_BLACKLIST_POLLING_INTERVAL_MS,
blacklistCacheTTLSecs: CABLES_BLACKLIST_CACHES_TTL_S,
blacklistCacheKey: CABLES_BLACKLIST_CACHE_KEY,

tokensHandleResponseCallback: async () => {
await this.setTokensMap();
},
},
},
);
Expand Down Expand Up @@ -255,6 +252,21 @@ export class Cables extends SimpleExchange implements IDex<any> {
}
}

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,
Expand Down Expand Up @@ -315,64 +327,6 @@ export class Cables extends SimpleExchange implements IDex<any> {
};
}

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,
Expand All @@ -398,8 +352,6 @@ export class Cables extends SimpleExchange implements IDex<any> {
side: SwapSide,
blockNumber: number,
): Promise<string[]> {
await this.setTokensMap();

if (!srcToken || !destToken) {
return [];
}
Expand All @@ -414,6 +366,7 @@ export class Cables extends SimpleExchange implements IDex<any> {
return [];
}

await this.setTokensMap();
const tokensAddr = (await this.getCachedTokensAddr()) || {};

return [
Expand Down Expand Up @@ -662,7 +615,7 @@ export class Cables extends SimpleExchange implements IDex<any> {
}

releaseResources?(): AsyncOrSync<void> {
if (this.rateFetcher) {
if (!this.dexHelper.config.isSlave && this.rateFetcher) {
this.rateFetcher.stop();
}
}
Expand Down Expand Up @@ -919,7 +872,7 @@ export class Cables extends SimpleExchange implements IDex<any> {
const cachedBlacklist = await this.dexHelper.cache.get(
this.dexKey,
this.network,
CABLES_BLACKLIST_CACHE_KEY,
this.rateFetcher.blacklistCacheKey,
);

if (cachedBlacklist) {
Expand Down
7 changes: 0 additions & 7 deletions src/dex/cables/rate-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export class CablesRateFetcher {
public blacklistCacheKey: string;
public blacklistCacheTTL: number;

tokensHandleResponseCallback: () => Promise<void>;

constructor(
private dexHelper: IDexHelper,
private dexKey: string,
Expand All @@ -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<CablesPairsResponse>(
dexHelper.httpRequest,
{
Expand Down Expand Up @@ -213,7 +208,5 @@ export class CablesRateFetcher {
this.tokensCacheTTL,
JSON.stringify(normalizedTokens),
);

await this.tokensHandleResponseCallback();
}
}
27 changes: 5 additions & 22 deletions src/dex/cables/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
};
Expand Down Expand Up @@ -115,8 +100,6 @@ export type CablesRateFetcherConfig = {
pairsCacheTTLSecs: number;
pricesCacheTTLSecs: number;
tokensCacheTTLSecs: number;

tokensHandleResponseCallback: () => Promise<void>;
};
};

Expand Down

0 comments on commit 5ec3319

Please sign in to comment.