Skip to content

Commit

Permalink
Merge pull request #919 from QuickSwap/feature/best-trade-zkevm
Browse files Browse the repository at this point in the history
Implement best trade in zkevm
  • Loading branch information
sameepsi authored Jul 20, 2023
2 parents a1ffd5b + 794db68 commit 7f72fb6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/components/Swap/SwapBestTrade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import useSwapRedirects from 'hooks/useSwapRedirect';
import callWallchainAPI from 'utils/wallchainService';
import ParaswapABI from 'constants/abis/ParaSwap_ABI.json';
import { ONE } from 'v3lib/utils';
import { SWAP_ROUTER_ADDRESS } from 'constants/v3/addresses';

const SwapBestTrade: React.FC<{
currencyBgClass?: string;
Expand Down Expand Up @@ -832,6 +833,9 @@ const SwapBestTrade: React.FC<{
: undefined;

useEffect(() => {
const bonusSwapRouterAddress = chainId
? SWAP_ROUTER_ADDRESS[chainId]
: undefined;
(async () => {
if (
swapIsReady &&
Expand All @@ -841,7 +845,8 @@ const SwapBestTrade: React.FC<{
account &&
library &&
chainId &&
approval === ApprovalState.APPROVED
approval === ApprovalState.APPROVED &&
bonusSwapRouterAddress
) {
setBonusRouteFound(false);
setBonusRouteLoading(true);
Expand Down
2 changes: 1 addition & 1 deletion src/config/zkmainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"swap": {
"available": true,
"bestTrade": false,
"bestTrade": true,
"proMode": false,
"limitOrder": false,
"crossChain": false
Expand Down
4 changes: 4 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1620,3 +1620,7 @@ export const LeaderBoardAnalytics = {
CHART_DURATIONS: [1, 7, 30],
CHART_DURATION_TEXTS: ['24H', '7D', '30D'],
};

export const paraswapAPIURL: { [chainId in ChainId]?: string } = {
[ChainId.ZKEVM]: 'https://api.orders.paraswap.io',
};
2 changes: 2 additions & 0 deletions src/constants/v3/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export const V2_ROUTER_ADDRESS: AddressMap = {

export const PARASWAP_PROXY_ROUTER_ADDRESS: AddressMap = {
[ChainId.MATIC]: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
[ChainId.ZKEVM]: '0xc8a21fcd5a100c3ecc037c97e2f9c53a8d3a02a1',
};

export const PARASWAP_ROUTER_ADDRESS: AddressMap = {
Expand Down Expand Up @@ -800,6 +801,7 @@ export const V2_BASES_TO_CHECK_TRADES_AGAINST: {
DC[ChainId.DOGECHAIN],
DD[ChainId.DOGECHAIN],
],
[ChainId.ZKEVM]: [],
};

export const StableCoins: { [ChainId: number]: Token[] } = {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useParaswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useMemo } from 'react';
import { useActiveWeb3React } from 'hooks';
import { constructSimpleSDK } from '@paraswap/sdk';
import { ChainId, Currency, ETHER, Token } from '@uniswap/sdk';
import { paraswapAPIURL } from 'constants/index';

const PARASWAP_NATIVE_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
export function getBestTradeCurrencyAddress(
Expand All @@ -21,6 +22,7 @@ export function useParaswap() {
const paraswapSDK = constructSimpleSDK({
network: <number>chainId,
fetch: window.fetch,
apiURL: paraswapAPIURL[chainId],
});

return paraswapSDK;
Expand Down

0 comments on commit 7f72fb6

Please sign in to comment.