Skip to content

Commit

Permalink
Merge pull request paraswap#495 from paraswap/BACK-1264
Browse files Browse the repository at this point in the history
feat(BACK-1264): add support for uniswapV3 on Base
  • Loading branch information
Verisana authored Sep 15, 2023
2 parents ca6167c + 69414df commit 579a33d
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 2 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": "2.35.2",
"version": "2.35.3",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
28 changes: 27 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ const baseConfigs: { [network: number]: BaseConfig } = {
rpcPollingBlocksBackToTriggerUpdate: 3,
forceRpcFallbackDexs: [],
},

[Network.ZKEVM]: {
network: Network.ZKEVM,
networkName: 'Polygon zkEVM',
Expand Down Expand Up @@ -347,6 +346,33 @@ const baseConfigs: { [network: number]: BaseConfig } = {
// FIXME: Not set properly
uniswapV2ExchangeRouterAddress: '',
},
[Network.BASE]: {
network: Network.BASE,
networkName: 'Base',
isTestnet: false,
nativeTokenName: 'Ether',
nativeTokenSymbol: 'ETH',
wrappedNativeTokenAddress: '0x4200000000000000000000000000000000000006',
hasEIP1559: false,
augustusAddress: '0x59C7C832e96D2568bea6db468C1aAdcbbDa08A52',
augustusRFQAddress: '0xa003dFBA51C9e1e56C67ae445b852bdEd7aC5EEd',
tokenTransferProxyAddress: '0x93aAAe79a53759cD164340E4C8766E4Db5331cD7',
multicallV2Address: '0xeDF6D2a16e8081F777eB623EeB4411466556aF3d',
privateHttpProvider: process.env.HTTP_PROVIDER_8453,
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
hashFlowDisabledMMs: [],
adapterAddresses: {
BaseAdapter01: '0x9F77bb28e97F093Aa6CbE37cE095C18605d98Af2',
BaseBuyAdapter: '0x8DE036910e34b0d8447Dd0D34C742636de1DDfEb',
},
uniswapV2ExchangeRouterAddress:
'0x75d199EfB540e47D27D52c62Da3E7daC2B9e834F',
uniswapV3EventLoggingSampleRate: 0,
rfqConfigs: {},
rpcPollingMaxAllowedStateDelayInBlocks: 5,
rpcPollingBlocksBackToTriggerUpdate: 3,
forceRpcFallbackDexs: [],
},
};

// Should not be used, except by internal test code
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export enum Network {
FANTOM = 250,
ARBITRUM = 42161,
OPTIMISM = 10,
BASE = 8453,
}
export const SUBGRAPH_TIMEOUT = 20 * 1000;

Expand Down
17 changes: 17 additions & 0 deletions src/dex/uniswap-v3/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
subgraphURL:
'https://api.thegraph.com/subgraphs/name/lynnshaoyu/uniswap-v3-avax',
},
[Network.BASE]: {
factory: '0x33128a8fC17869897dcE68Ed026d694621f6FDfD',
quoter: '0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a',
router: '0xaeE2b8d4A154e36f479dAeCe3FB3e6c3c03d396E',
supportedFees: SUPPORTED_FEES,
stateMulticall: '0x7160f736c52e1e78e92FD4eE4D73e21A7Cf4F950',
uniswapMulticall: '0x091e99cb1C49331a94dD62755D168E941AbD0693',
chunksCount: 10,
initRetryFrequency: 10,
initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
subgraphURL:
'https://api.studio.thegraph.com/query/48211/uniswap-v3-base/version/latest',
},
},
SushiSwapV3: {
[Network.MAINNET]: {
Expand Down Expand Up @@ -283,4 +296,8 @@ export const Adapters: Record<number, AdapterMappings> = {
[SwapSide.SELL]: [{ name: 'AvalancheAdapter02', index: 5 }],
[SwapSide.BUY]: [{ name: 'AvalancheBuyAdapter', index: 6 }],
},
[Network.BASE]: {
[SwapSide.SELL]: [{ name: 'BaseAdapter01', index: 1 }],
[SwapSide.BUY]: [{ name: 'BaseBuyAdapter', index: 1 }],
},
};
95 changes: 95 additions & 0 deletions src/dex/uniswap-v3/uniswap-v3-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,101 @@ describe('UniswapV3 E2E', () => {
);
});

describe('UniswapV3 Base', () => {
const network = Network.BASE;
const tokens = Tokens[network];
const holders = Holders[network];
const provider = new StaticJsonRpcProvider(
generateConfig(network).privateHttpProvider,
network,
);

const tokenASymbol: string = 'PRIME';
const tokenBSymbol: string = 'WETH';
const nativeTokenSymbol = NativeTokenSymbols[network];

const tokenAAmount: string = '1000000000000000000';
const tokenBAmount: string = '1000000000000000000';
const nativeTokenAmount = '1000000000000000000';

const sideToContractMethods = new Map([
[
SwapSide.SELL,
[
// ContractMethod.simpleSwap,
ContractMethod.multiSwap,
// ContractMethod.megaSwap,
],
],
[
SwapSide.BUY,
[
// ContractMethod.simpleBuy,
// ContractMethod.buy
],
],
]);

sideToContractMethods.forEach((contractMethods, side) =>
contractMethods.forEach((contractMethod: ContractMethod) => {
describe(`${contractMethod}`, () => {
it(`${network} ${side} ${contractMethod} ${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
await testE2E(
tokens[nativeTokenSymbol],
tokens[tokenASymbol],
holders[nativeTokenSymbol],
side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${network} ${side} ${contractMethod} ${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[nativeTokenSymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${network} ${side} ${contractMethod} ${tokenBSymbol} -> ${tokenASymbol}`, async () => {
await testE2E(
tokens[tokenBSymbol],
tokens[tokenASymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenBAmount : tokenAAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${network} ${side} ${contractMethod} ${tokenASymbol} -> ${tokenBSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[tokenBSymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
});
}),
);
});

describe('UniswapV3 Avalanche', () => {
const network = Network.AVALANCHE;
const tokens = Tokens[network];
Expand Down
3 changes: 3 additions & 0 deletions src/dex/weth/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const WethConfig: DexConfigMap<DexParams> = {
[Network.ZKEVM]: {
poolGasCost: WethGasCost,
},
[Network.BASE]: {
poolGasCost: WethGasCost,
},
},
Wbnb: {
[Network.BSC]: {
Expand Down
17 changes: 17 additions & 0 deletions tests/constants-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,17 @@ export const Tokens: {
decimals: 6,
},
},
[Network.BASE]: {
PRIME: {
address: '0xfA980cEd6895AC314E7dE34Ef1bFAE90a5AdD21b',
decimals: 18,
},
WETH: {
address: '0x4200000000000000000000000000000000000006',
decimals: 18,
},
ETH: { address: ETHER_ADDRESS, decimals: 18 },
},
};

export const Holders: {
Expand Down Expand Up @@ -1102,6 +1113,11 @@ export const Holders: {
WBTC: '0x99b31498b0a1dae01fc3433e3cb60f095340935c',
USDC: '0x99b31498b0a1dae01fc3433e3cb60f095340935c',
},
[Network.BASE]: {
WETH: '0x4bb6b2efe7036020ba6f02a05602546c9f25bf28',
PRIME: '0x956bcc6b56c99db382d9d97a30ba5f1402144b3e',
ETH: '0xdd9176ea3e7559d6b68b537ef555d3e89403f742',
},
};

export const SmartTokens = Object.keys(Tokens).reduce((acc, _network) => {
Expand All @@ -1126,4 +1142,5 @@ export const NativeTokenSymbols: { [network: number]: string } = {
[Network.FANTOM]: 'FTM',
[Network.ARBITRUM]: 'ETH',
[Network.OPTIMISM]: 'ETH',
[Network.BASE]: 'ETH',
};

0 comments on commit 579a33d

Please sign in to comment.