Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/pub-sub-swaap-…
Browse files Browse the repository at this point in the history
…v2-bebop-cables
  • Loading branch information
KanievskyiDanylo committed Dec 27, 2024
2 parents 32e1a7b + dec7b3b commit d5a86e0
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 26 deletions.
10 changes: 9 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ HTTP_PROVIDER_43114=

TENDERLY_TOKEN=
TENDERLY_ACCOUNT_ID=
TENDERLY_PROJECT=
TENDERLY_PROJECT=


API_KEY_BEBOP_AUTH_NAME=paraswap
API_KEY_BEBOP_AUTH_TOKEN=test
API_KEY_HASHFLOW_AUTH_TOKEN=test
API_KEY_SWAAP_V2_AUTH_TOKEN=test
API_KEY_DEXALOT_AUTH_TOKEN=test
API_KEY_SMARDEX_SUBGRAPH=test
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type BaseConfig = {
idleDaoAuthToken?: string;
swaapV2AuthToken?: string;
dexalotAuthToken?: string;
bebopAuthName?: string;
bebopAuthToken?: string;
forceRpcFallbackDexs: string[];
};
Expand Down Expand Up @@ -74,6 +75,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
rpcPollingBlocksBackToTriggerUpdate: 0,
swaapV2AuthToken: process.env.API_KEY_SWAAP_V2_AUTH_TOKEN || '',
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
bebopAuthName: process.env.API_KEY_BEBOP_AUTH_NAME || '',
bebopAuthToken: process.env.API_KEY_BEBOP_AUTH_TOKEN || '',
idleDaoAuthToken: process.env.API_KEY_IDLEDAO_AUTH_TOKEN || '',
hashFlowDisabledMMs:
Expand Down Expand Up @@ -147,6 +149,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
multicallV2Address: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D',
privateHttpProvider: process.env.HTTP_PROVIDER_56,
augustusV6Address: '0x6a000f20005980200259b80c5102003040001068',
bebopAuthName: process.env.API_KEY_BEBOP_AUTH_NAME || '',
bebopAuthToken: process.env.API_KEY_BEBOP_AUTH_TOKEN || '',
executorsAddresses: {
Executor01: '0x000010036C0190E009a000d0fc3541100A07380A',
Expand Down Expand Up @@ -301,6 +304,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
Executor03: '0xe009F00e200A090090fC70e02d70B232000c0802',
},
dexalotAuthToken: process.env.API_KEY_DEXALOT_AUTH_TOKEN || '',
bebopAuthName: process.env.API_KEY_BEBOP_AUTH_NAME || '',
bebopAuthToken: process.env.API_KEY_BEBOP_AUTH_TOKEN || '',
adapterAddresses: {
ArbitrumAdapter01: '0x369A2FDb910d432f0a07381a5E3d27572c876713',
Expand Down Expand Up @@ -348,6 +352,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
uniswapV2ExchangeRouterAddress:
'0xB41dD984730dAf82f5C41489E21ac79D5e3B61bC',
uniswapV3EventLoggingSampleRate: 0,
bebopAuthName: process.env.API_KEY_BEBOP_AUTH_NAME || '',
bebopAuthToken: process.env.API_KEY_BEBOP_AUTH_TOKEN || '',
rfqConfigs: {},
rpcPollingMaxAllowedStateDelayInBlocks: 5,
Expand Down Expand Up @@ -431,6 +436,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
multicallV2Address: '0xeDF6D2a16e8081F777eB623EeB4411466556aF3d',
privateHttpProvider: process.env.HTTP_PROVIDER_8453,
dexalotAuthToken: process.env.API_KEY_DEXALOT_AUTH_TOKEN || '',
bebopAuthName: process.env.API_KEY_BEBOP_AUTH_NAME || '',
bebopAuthToken: process.env.API_KEY_BEBOP_AUTH_TOKEN || '',
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
swaapV2AuthToken: process.env.API_KEY_SWAAP_V2_AUTH_TOKEN || '',
Expand Down Expand Up @@ -528,6 +534,7 @@ export function generateConfig(network: number): Config {
idleDaoAuthToken: baseConfig.idleDaoAuthToken,
swaapV2AuthToken: baseConfig.swaapV2AuthToken,
dexalotAuthToken: baseConfig.dexalotAuthToken,
bebopAuthName: baseConfig.bebopAuthName,
bebopAuthToken: baseConfig.bebopAuthToken,
hashFlowDisabledMMs: baseConfig.hashFlowDisabledMMs,
forceRpcFallbackDexs: baseConfig.forceRpcFallbackDexs,
Expand Down
12 changes: 12 additions & 0 deletions src/dex/bebop/bebop-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
100,
);
});
it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
Expand All @@ -63,6 +67,10 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
100,
);
});
it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
Expand All @@ -76,6 +84,10 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
100,
);
});
});
Expand Down
40 changes: 33 additions & 7 deletions src/dex/bebop/bebop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { Interface } from 'ethers/lib/utils';
import { RateFetcher } from './rate-fetcher';
import {
BEBOP_API_URL,
BEBOP_AUTH_NAME,
BEBOP_ERRORS_CACHE_KEY,
BEBOP_GAS_COST,
BEBOP_INIT_TIMEOUT_MS,
Expand All @@ -55,7 +54,7 @@ import {
} from './constants';
import BigNumber from 'bignumber.js';
import { getBigNumberPow } from '../../bignumber-constants';
import { utils } from 'ethers';
import { ethers, utils } from 'ethers';
import qs from 'qs';
import { isEqual } from 'lodash';

Expand All @@ -76,6 +75,7 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
private tokensAddrCacheKey: string;

private bebopAuthToken: string;
private bebopAuthName: string;

logger: Logger;

Expand All @@ -92,9 +92,19 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
this.pricesCacheKey = `prices`;
this.tokensAddrCacheKey = `tokens_addr`;
const token = this.dexHelper.config.data.bebopAuthToken;
if (!token) {
throw new Error('Bebop auth token is not set');
}
const name = this.dexHelper.config.data.bebopAuthName;

assert(
token !== undefined,
'Bebop auth token is not specified with env variable',
);

assert(
name !== undefined,
'Bebop auth name is not specified with env variable',
);

this.bebopAuthName = name;
this.bebopAuthToken = token;

this.rateFetcher = new RateFetcher(
Expand All @@ -119,7 +129,7 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
BEBOP_WS_API_URL +
`/pmm/${BebopConfig['Bebop'][network].chainName}/v3/pricing?format=protobuf`,
headers: {
name: BEBOP_AUTH_NAME,
name: this.bebopAuthName,
authorization: this.bebopAuthToken,
},
},
Expand Down Expand Up @@ -650,12 +660,28 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
srcAmount, // modify filledTakerAmount to make insertFromAmount work
]);

const fromAmount = ethers.utils.defaultAbiCoder.encode(
['uint256'],
[srcAmount],
);

const filledTakerAmountIndex = exchangeData
.replace('0x', '')
.lastIndexOf(fromAmount.replace('0x', ''));

const filledTakerAmountPos =
(filledTakerAmountIndex !== -1
? filledTakerAmountIndex
: exchangeData.length) / 2;

return {
exchangeData: exchangeData,
needWrapNative: this.needWrapNative,
dexFuncHasRecipient: true,
targetExchange: this.settlementAddress,
returnAmountPos: undefined,
sendEthButSupportsInsertFromAmount: true,
insertFromAmountPos: filledTakerAmountPos,
};
} else {
throw new Error('Not supported method');
Expand All @@ -681,7 +707,7 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
receiver_address: utils.getAddress(options.recipient),
gasless: false,
skip_validation: true,
source: BEBOP_AUTH_NAME,
source: this.bebopAuthName,
};

try {
Expand Down
1 change: 0 additions & 1 deletion src/dex/bebop/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const BEBOP_TOKENS_POLLING_INTERVAL_MS = 30 * 1000;
export const BEBOP_API_URL = 'https://api.bebop.xyz';
export const BEBOP_WS_API_URL = 'wss://api.bebop.xyz';
export const BEBOP_GAS_COST = 120_000;
export const BEBOP_AUTH_NAME = 'paraswap';
export const BEBOP_QUOTE_TIMEOUT_MS = 3000;
export const BEBOP_ERRORS_CACHE_KEY = 'errors';
export const BEBOP_RESTRICTED_CACHE_KEY = 'restricted';
Expand Down
1 change: 1 addition & 0 deletions src/dex/cables/cables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export class Cables extends SimpleExchange implements IDex<any> {
targetExchange: this.mainnetRFQAddress,
returnAmountPos: undefined,
insertFromAmountPos: filledAmountPos,
sendEthButSupportsInsertFromAmount: true,
};
}

Expand Down
7 changes: 7 additions & 0 deletions src/dex/fluid-dex/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ export const FluidDexConfig: DexConfigMap<DexParams> = {
dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
},
},
[Network.ARBITRUM]: {
commonAddresses: {
liquidityProxy: '0x52Aa899454998Be5b000Ad077a46Bbe360F4e497',
resolver: '0xb8f526718FF58758E256D9aD86bC194a9ff5986D',
dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
},
},
},
};

Expand Down
38 changes: 38 additions & 0 deletions src/dex/fluid-dex/fluid-dex-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,44 @@ describe('FluidDex E2E', () => {
);
});
});

describe('Arbitrum', () => {
const network = Network.ARBITRUM;

describe('ETH -> wstETH', () => {
const tokenASymbol: string = 'wstETH';
const tokenBSymbol: string = 'ETH';

const tokenAAmount: string = '1000000000000000';
const tokenBAmount: string = '1000000000000000';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
);
});

describe('ETH -> weETH', () => {
const tokenBSymbol: string = 'ETH';
const tokenASymbol: string = 'weETH';

const tokenAAmount: string = '1000000000000000';
const tokenBAmount: string = '1000000000000000';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
);
});
});
});

function NewColReservesOne(): CollateralReserves {
Expand Down
1 change: 1 addition & 0 deletions src/dex/solidly/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const SolidlyConfig: DexConfigMap<DexParams> = {
// There is no subgraph for Aerodrome
factoryAddress: '0x420DD381b31aEf6683db6B902084cB0FFECe40Da',
router: '0xDCf4EE5B700e2a5Fec458e06B763A4a3E3004494',
subgraphURL: '7uEwiKmfbRQqV8Ec9nvdKrMFVFQv5qaM271gdBvHtywj',
initCode:
'0x1a8f01f7eab324003d9388f229ea17991eee9c9d14586f429799f3656790eba0',
poolGasCost: 180 * 1000,
Expand Down
20 changes: 16 additions & 4 deletions src/dex/solidly/solidly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,15 +445,23 @@ export class Solidly extends UniswapV2 {
if (!this.subgraphURL) return [];

let stableFieldKey = '';
let skipReserveCheck = false;

if (this.dexKey.toLowerCase() === 'solidly') {
stableFieldKey = 'stable';
} else if (this.dexKey.toLowerCase() !== 'solidlyv2') {
stableFieldKey = 'isStable';
}

// aerodrome subgraph has broken reserve and other volume fields with all 0s
if (this.dexKey.toLowerCase() === 'aerodrome') {
skipReserveCheck = true;
}

const query = `query ($token: Bytes!, $count: Int) {
pools0: pairs(first: $count, orderBy: reserveUSD, orderDirection: desc, where: {token0: $token, reserve0_gt: 1, reserve1_gt: 1}) {
pools0: pairs(first: $count, orderBy: reserveUSD, orderDirection: desc, where: {token0: $token ${
skipReserveCheck ? '' : ', reserve0_gt: 1, reserve1_gt: 1'
}}) {
id
${stableFieldKey}
token0 {
Expand All @@ -466,7 +474,9 @@ export class Solidly extends UniswapV2 {
}
reserveUSD
}
pools1: pairs(first: $count, orderBy: reserveUSD, orderDirection: desc, where: {token1: $token, reserve0_gt: 1, reserve1_gt: 1}) {
pools1: pairs(first: $count, orderBy: reserveUSD, orderDirection: desc, where: {token1: $token ${
skipReserveCheck ? '' : ', reserve0_gt: 1, reserve1_gt: 1'
}}) {
id
${stableFieldKey}
token0 {
Expand Down Expand Up @@ -502,7 +512,8 @@ export class Solidly extends UniswapV2 {
decimals: parseInt(pool.token1.decimals),
},
],
liquidityUSD: parseFloat(pool.reserveUSD),
liquidityUSD:
parseFloat(pool.reserveUSD) || (skipReserveCheck ? 10e5 : 0),
}));

const pools1 = _.map(data.pools1, pool => ({
Expand All @@ -515,7 +526,8 @@ export class Solidly extends UniswapV2 {
decimals: parseInt(pool.token0.decimals),
},
],
liquidityUSD: parseFloat(pool.reserveUSD),
liquidityUSD:
parseFloat(pool.reserveUSD) || (skipReserveCheck ? 10e5 : 0),
}));

return _.slice(
Expand Down
Loading

0 comments on commit d5a86e0

Please sign in to comment.