Skip to content

Commit

Permalink
Merge pull request #881 from paraswap/feat/BACK-1825
Browse files Browse the repository at this point in the history
fix: always rely on WETH instead of ETH on Bebop
  • Loading branch information
KanievskyiDanylo authored Jan 20, 2025
2 parents accfda9 + 17ce640 commit 9aa1547
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paraswap/dex-lib",
"version": "4.0.21",
"version": "4.0.22",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
32 changes: 18 additions & 14 deletions src/dex/bebop/bebop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
NumberAsString,
DexExchangeParam,
} from '../../types';
import { SwapSide, Network, ETHER_ADDRESS } from '../../constants';
import { SwapSide, Network } from '../../constants';
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
import { getDexKeysWithNetwork, Utils } from '../../utils';
import { IDex } from '../../dex/idex';
Expand Down Expand Up @@ -56,11 +56,10 @@ import BigNumber from 'bignumber.js';
import { getBigNumberPow } from '../../bignumber-constants';
import { ethers, utils } from 'ethers';
import qs from 'qs';
import { isEqual } from 'lodash';

export class Bebop extends SimpleExchange implements IDex<BebopData> {
readonly hasConstantPriceLargeAmounts = false;
readonly needWrapNative = false;
readonly needWrapNative = true;

readonly isFeeOnTransferSupported = false;
readonly isStatePollingDex = true;
Expand Down Expand Up @@ -186,11 +185,7 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
srcToken.address.toLowerCase(),
destToken.address.toLowerCase(),
]);
const nativeWrappedSet = new Set([
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase(),
ETHER_ADDRESS.toLowerCase(),
]);
if (tokensSet.size < 2 || isEqual(tokensSet, nativeWrappedSet)) {
if (tokensSet.size < 2) {
return [];
}

Expand Down Expand Up @@ -281,11 +276,14 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
// across DEXes. It is recommended to use
// ${dexKey}_${poolAddress} as a poolIdentifier
async getPoolIdentifiers(
srcToken: Token,
destToken: Token,
_srcToken: Token,
_destToken: Token,
side: SwapSide,
blockNumber: number,
): Promise<string[]> {
const srcToken = this.dexHelper.config.wrapETH(_srcToken);
const destToken = this.dexHelper.config.wrapETH(_destToken);

if (
(await this.calculateInstructions(srcToken, destToken, side)).length > 0
) {
Expand Down Expand Up @@ -387,8 +385,8 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
// should be used. If limitPools is undefined then
// any pools can be used.
async getPricesVolume(
srcToken: Token,
destToken: Token,
_srcToken: Token,
_destToken: Token,
amounts: bigint[],
side: SwapSide,
blockNumber: number,
Expand All @@ -399,6 +397,9 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
return null;
}

const srcToken = this.dexHelper.config.wrapETH(_srcToken);
const destToken = this.dexHelper.config.wrapETH(_destToken);

try {
let pools = limitPools
? limitPools.filter(
Expand Down Expand Up @@ -696,14 +697,17 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {

async preProcessTransaction(
optimalSwapExchange: OptimalSwapExchange<BebopData>,
srcToken: Token,
destToken: Token,
_srcToken: Token,
_destToken: Token,
side: SwapSide,
options: PreprocessTransactionOptions,
): Promise<[OptimalSwapExchange<BebopData>, ExchangeTxInfo]> {
const isSell = side === SwapSide.SELL;
const isBuy = side === SwapSide.BUY;

const srcToken = this.dexHelper.config.wrapETH(_srcToken);
const destToken = this.dexHelper.config.wrapETH(_destToken);

const params = {
sell_tokens: utils.getAddress(srcToken.address),
buy_tokens: utils.getAddress(destToken.address),
Expand Down
19 changes: 2 additions & 17 deletions src/dex/bebop/rate-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ETHER_ADDRESS, Network } from '../../constants';
import { Network } from '../../constants';
import { IDexHelper } from '../../dex-helper';
import { Fetcher } from '../../lib/fetcher/fetcher';
import { validateAndCast, ValidationError } from '../../lib/validators';
Expand All @@ -10,11 +10,7 @@ import {
BebopRateFetcherConfig,
BebopTokensResponse,
} from './types';
import {
BebopPricingUpdate,
pricesResponseValidator,
tokensResponseValidator,
} from './validators';
import { BebopPricingUpdate, tokensResponseValidator } from './validators';
import { WebSocketFetcher } from '../../lib/fetcher/wsFetcher';
import { utils } from 'ethers';

Expand Down Expand Up @@ -156,20 +152,9 @@ export class RateFetcher {
}

private handlePricesResponse(resp: BebopPricingResponse): void {
const wethAddress =
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
const normalizedPrices: BebopPricingResponse = {};
for (const [pair, levels] of Object.entries(resp)) {
normalizedPrices[pair.toLowerCase()] = levels;
const [base, quote] = pair.split('/');
// Also enter native token prices. Pricing doesn't come with these
if (
base.toLowerCase() === wethAddress ||
quote.toLowerCase() === wethAddress
) {
const nativePair = pair.replace(base, ETHER_ADDRESS);
normalizedPrices[nativePair.toLowerCase()] = levels;
}
}

this.dexHelper.cache.setex(
Expand Down

0 comments on commit 9aa1547

Please sign in to comment.