Skip to content

Commit

Permalink
fix requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Oct 3, 2023
1 parent 93a94ba commit 05bc393
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/dex/dexalot/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DexParams } from './types';
import { DexConfigMap, AdapterMappings } from '../../types';
import { Network, SwapSide } from '../../constants';
import { Network } from '../../constants';

export const DexalotConfig: DexConfigMap<DexParams> = {
Dexalot: {
Expand Down
63 changes: 44 additions & 19 deletions src/dex/dexalot/dexalot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import { BI_MAX_UINT256 } from '../../bigint-constants';
import { ethers } from 'ethers';
import BigNumber from 'bignumber.js';
import { Method } from '../../dex-helper/irequest-wrapper';
import { normalizeTokenAddress } from '../swaap-v2/utils';

export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
readonly isStatePollingDex = true;
Expand Down Expand Up @@ -196,8 +195,14 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
return null;
}

getIdentifier(baseSymbol: string, quoteSymbol: string) {
// return `${this.dexKey}_${baseSymbol}_${quoteSymbol}`.toLowerCase();
getIdentifier(srcAddress: Address, destAddress: Address) {
// const sortedAddresses =
// srcAddress < destAddress
// ? [srcAddress, destAddress]
// : [destAddress, srcAddress];
//
// return `${this.dexKey}_${sortedAddresses[0].toLowerCase()}_${sortedAddresses[1].toLowerCase()}`;

// To disable Dexalot in multi/mega routes
return this.dexKey;
}
Expand All @@ -215,7 +220,13 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
if (!pairData) {
return [];
}
return [this.getIdentifier(pairData.base, pairData.quote)];

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

return [this.getIdentifier(
tokensAddr[pairData.base.toLowerCase()],
tokensAddr[pairData.quote.toLowerCase()],
)];
}

async getCachedPairs(): Promise<PairDataMap | null> {
Expand Down Expand Up @@ -377,7 +388,18 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
return null;
}

if (limitPools && limitPools.length !== 1) {
const pools = limitPools
? limitPools.filter(
p =>
p ===
this.getIdentifier(
normalizedSrcToken.address,
normalizedDestToken.address,
),
)
: await this.getPoolIdentifiers(srcToken, destToken, side, blockNumber);

if (pools.length === 0) {
return null;
}

Expand All @@ -394,8 +416,15 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
return null;
}

const tokensAddr = (await this.getCachedTokensAddr()) || {};
const pairKey = `${pairData.base}/${pairData.quote}`.toLowerCase();
if (!(pairKey in priceMap)) {
if (
!(pairKey in priceMap)
|| !pools.includes(this.getIdentifier(
tokensAddr[pairData.base.toLowerCase()],
tokensAddr[pairData.quote.toLowerCase()],
))
) {
return null;
}

Expand Down Expand Up @@ -445,8 +474,8 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
];
} catch (e: unknown) {
this.logger.error(
`Error_getPricesVolume ${srcToken.symbol || srcToken.address}, ${
destToken.symbol || destToken.address
`Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${
destToken.address || destToken.symbol
}, ${side}:`,
e,
);
Expand Down Expand Up @@ -477,16 +506,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
}: user=${options.txOrigin.toLowerCase()} is blacklisted`,
);
}
if (await this.isRateLimited(options.txOrigin)) {
this.logger.warn(
`${this.dexKey}-${this.network}: rate limited TX Origin address '${options.txOrigin}' trying to build a transaction. Bailing...`,
);
throw new Error(
`${this.dexKey}-${
this.network
}: user=${options.txOrigin.toLowerCase()} is rate limited`,
);
}

if (BigInt(optimalSwapExchange.srcAmount) === 0n) {
throw new Error('getFirmRate failed with srcAmount === 0');
}
Expand Down Expand Up @@ -786,6 +806,11 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
return blacklist.includes(txOrigin.toLowerCase());
}

// To not show pricing for rate limited users
if(await this.isRateLimited(txOrigin)) {
return true;
}

return false;
}

Expand Down Expand Up @@ -862,7 +887,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
tokenAddress: Address,
limit: number,
): Promise<PoolLiquidity[]> {
const normalizedTokenAddress = normalizeTokenAddress(tokenAddress);
const normalizedTokenAddress = this.normalizeAddress(tokenAddress);
const pairs = (await this.getCachedPairs()) || {};
this.tokensMap = (await this.getCachedTokens()) || {};
const tokensAddr = (await this.getCachedTokensAddr()) || {};
Expand Down
2 changes: 1 addition & 1 deletion tests/constants-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ export const Holders: {
TSD: '0x691A89db352B72dDb249bFe16503494eC0D920A4',
THO: '0xc40d16c47394a506d451475c8a7c46c1175c1da1',
aAvaUSDT: '0x50B1Ba98Cf117c9682048D56628B294ebbAA4ec2',
USDT: '0x4aeFa39caEAdD662aE31ab0CE7c8C2c9c0a013E8',
USDT: '0x4a58555884297dcd9d2198c9fec52b4cabc90fc6',
aAvaWAVAX: '0x1B18Df70863636AEe4BfBAb6F7C70ceBCA9bA404',
oldFRAX: '0x4e3376018add04ebe4c46bf6f924ddec8c67aa7b',
newFRAX: '0x4e3376018add04ebe4c46bf6f924ddec8c67aa7b',
Expand Down

0 comments on commit 05bc393

Please sign in to comment.