Skip to content

Commit

Permalink
feat: add support for Ethereum and Sepolia chains
Browse files Browse the repository at this point in the history
  • Loading branch information
therealemjy committed Nov 7, 2023
1 parent a52e640 commit 911d245
Show file tree
Hide file tree
Showing 24 changed files with 135 additions and 75 deletions.
12 changes: 10 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
VITE_ENVIRONMENT=testnet
VITE_ENVIRONMENT=
# BSC mainnet RPC
VITE_RPC_HTTP_URL_BSC_MAINNET=
VITE_RPC_WEBSOCKET_URL_BSC_MAINNET=
VITE_RPC_HTTP_URL_BSC_TESTNET=
# BSC testnet RPC
VITE_RPC_WEBSOCKET_URL_BSC_TESTNET=
VITE_RPC_HTTP_URL_BSC_TESTNET=
# Ethereum RPC
VITE_RPC_WEBSOCKET_URL_ETHEREUM=
VITE_RPC_HTTP_URL_ETHEREUM=
# Sepolia (Ethereum testnet) RPC
VITE_RPC_WEBSOCKET_URL_SEPOLIA=
VITE_RPC_HTTP_URL_SEPOLIA=
10 changes: 5 additions & 5 deletions src/clients/api/queries/useGetTreasuryTotals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { useAuth } from 'context/AuthContext';

// Note: this is a temporary fix. Once we start refactoring this part we should
// probably fetch the treasury address using the Comptroller contract
const TREASURY_ADDRESSES = {
56: '0xF322942f644A996A617BD29c16bd7d231d9F35E9',
const TREASURY_ADDRESSES = new Map([
[56, '0xF322942f644A996A617BD29c16bd7d231d9F35E9'],
// When querying comptroller.treasuryAddress() we get an empty address back,
// so for now I've let it as it is
97: '0x0000000000000000000000000000000000000000',
};
[97, '0x0000000000000000000000000000000000000000'],
]);

export interface Data {
treasurySupplyBalanceCents: BigNumber;
Expand All @@ -32,7 +32,7 @@ export interface UseGetTreasuryTotalsOutput {

const useGetTreasuryTotals = (): UseGetTreasuryTotalsOutput => {
const { accountAddress, chainId } = useAuth();
const treasuryAddress = chainId && TREASURY_ADDRESSES[chainId];
const treasuryAddress = TREASURY_ADDRESSES.get(chainId);

const { data: getPoolsData, isLoading: isGetPoolsDataLoading } = useGetIsolatedPools({
accountAddress,
Expand Down
5 changes: 3 additions & 2 deletions src/clients/web3/Web3Wrapper/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import localConfig from 'config';
import { ChainId } from 'types';
import { Chain, configureChains, createConfig } from 'wagmi';
import { bsc, bscTestnet } from 'wagmi/chains';
import { bsc, bscTestnet, mainnet, sepolia } from 'wagmi/chains';
import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet';
import { InjectedConnector } from 'wagmi/connectors/injected';
import { MetaMaskConnector } from 'wagmi/connectors/metaMask';
Expand All @@ -12,7 +12,8 @@ import { WALLET_CONNECT_PROJECT_ID } from 'constants/walletConnect';

import { BinanceWalletConnector } from './binanceWalletConnector';

export const chains: Chain[] = localConfig.isOnTestnet ? [bscTestnet] : [bsc];
// Note: the first chain listed will be used as the default chain
export const chains: Chain[] = localConfig.isOnTestnet ? [bscTestnet, sepolia] : [bsc, mainnet];

const { publicClient, webSocketPublicClient } = configureChains(
chains,
Expand Down
5 changes: 1 addition & 4 deletions src/components/BscLink/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ export const BscLink: React.FC<BscLinkProps> = ({

return (
<div className={cn('inline-block text-sm font-semibold text-blue', className)}>
<Link
href={chainId && generateBscScanUrl({ hash, urlType, chainId })}
className="flex items-center"
>
<Link href={generateBscScanUrl({ hash, urlType, chainId })} className="flex items-center">
{content}

<Icon name="open" className="ml-2 text-inherit" />
Expand Down
31 changes: 27 additions & 4 deletions src/config/envVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,46 @@ export const ENV_VARIABLES = {
typeof process !== 'undefined'
? process.env.VITE_ENVIRONMENT
: import.meta.env.VITE_ENVIRONMENT,

// BSC testnet RPC
VITE_RPC_HTTP_URL_BSC_MAINNET:
typeof process !== 'undefined'
? process.env.VITE_RPC_HTTP_URL_BSC_MAINNET
: import.meta.env.VITE_RPC_HTTP_URL_BSC_MAINNET,
VITE_RPC_HTTP_URL_BSC_TESTNET:
typeof process !== 'undefined'
? process.env.VITE_RPC_HTTP_URL_BSC_TESTNET
: import.meta.env.VITE_RPC_HTTP_URL_BSC_TESTNET,
VITE_RPC_WEBSOCKET_URL_BSC_MAINNET:
typeof process !== 'undefined'
? process.env.VITE_RPC_WEBSOCKET_URL_BSC_MAINNET
: import.meta.env.VITE_RPC_WEBSOCKET_URL_BSC_MAINNET,

// BSC mainnet RPC
VITE_RPC_HTTP_URL_BSC_TESTNET:
typeof process !== 'undefined'
? process.env.VITE_RPC_HTTP_URL_BSC_TESTNET
: import.meta.env.VITE_RPC_HTTP_URL_BSC_TESTNET,
VITE_RPC_WEBSOCKET_URL_BSC_TESTNET:
typeof process !== 'undefined'
? process.env.VITE_RPC_WEBSOCKET_URL_BSC_TESTNET
: import.meta.env.VITE_RPC_WEBSOCKET_URL_BSC_TESTNET,

// Ethereum RPC
VITE_RPC_HTTP_URL_ETHEREUM:
typeof process !== 'undefined'
? process.env.VITE_RPC_HTTP_URL_ETHEREUM
: import.meta.env.VITE_RPC_HTTP_URL_ETHEREUM,
VITE_RPC_WEBSOCKET_URL_ETHEREUM:
typeof process !== 'undefined'
? process.env.VITE_RPC_WEBSOCKET_URL_ETHEREUM
: import.meta.env.VITE_RPC_WEBSOCKET_URL_ETHEREUM,
// Sepolia (Ethereum testnet) RPC
VITE_RPC_HTTP_URL_SEPOLIA:
typeof process !== 'undefined'
? process.env.VITE_RPC_HTTP_URL_SEPOLIA
: import.meta.env.VITE_RPC_HTTP_URL_SEPOLIA,
VITE_RPC_WEBSOCKET_URL_SEPOLIA:
typeof process !== 'undefined'
? process.env.VITE_RPC_WEBSOCKET_URL_SEPOLIA
: import.meta.env.VITE_RPC_WEBSOCKET_URL_SEPOLIA,

// Third-parties
VITE_SENTRY_DSN:
typeof process !== 'undefined' ? process.env.VITE_SENTRY_DSN : import.meta.env.VITE_SENTRY_DSN,
Expand Down
8 changes: 8 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ const rpcUrls = isLocalServer
http: ENV_VARIABLES.VITE_RPC_HTTP_URL_BSC_TESTNET,
webSocket: ENV_VARIABLES.VITE_RPC_WEBSOCKET_URL_BSC_TESTNET,
},
[ChainId.ETHEREUM]: {
http: ENV_VARIABLES.VITE_RPC_HTTP_URL_ETHEREUM,
webSocket: ENV_VARIABLES.VITE_RPC_WEBSOCKET_URL_ETHEREUM,
},
[ChainId.SEPOLIA]: {
http: ENV_VARIABLES.VITE_RPC_HTTP_URL_SEPOLIA,
webSocket: ENV_VARIABLES.VITE_RPC_WEBSOCKET_URL_SEPOLIA,
},
}
: RPC_URLS;

Expand Down
2 changes: 2 additions & 0 deletions src/constants/bsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const BLOCKS_PER_DAY = (60 / (BLOCK_TIME_MS / 1000)) * 60 * 24;
export const EXPLORER_URLS = {
[ChainId.BSC_MAINNET]: 'https://bscscan.com',
[ChainId.BSC_TESTNET]: 'https://testnet.bscscan.com',
[ChainId.ETHEREUM]: 'https://etherscan.io/',
[ChainId.SEPOLIA]: 'https://sepolia.etherscan.io/',
};
8 changes: 8 additions & 0 deletions src/constants/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ export const RPC_URLS: {
http: 'https://bsc-testnet.nodereal.io/v1/7fab7575d1c34150a9ee582167ffac6f',
webSocket: 'wss://bsc-testnet.nodereal.io/ws/v1/7fab7575d1c34150a9ee582167ffac6f',
},
[ChainId.ETHEREUM]: {
http: 'https://eth-mainnet.nodereal.io/v1/7fab7575d1c34150a9ee582167ffac6f',
webSocket: 'wss://eth-mainnet.nodereal.io/ws/v1/7fab7575d1c34150a9ee582167ffac6f',
},
[ChainId.SEPOLIA]: {
http: 'https://ethereum-sepolia.publicnode.com',
webSocket: 'wss://ethereum-sepolia.publicnode.com',
},
};
3 changes: 1 addition & 2 deletions src/containers/Layout/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Footer: React.FC = () => {
symbol: 'XVS',
});

const explorerUrl = chainId && EXPLORER_URLS[chainId];
const explorerUrl = EXPLORER_URLS[chainId];

return (
<footer className="flex h-14 flex-none items-center justify-between bg-background px-4 sm:justify-end md:px-6 xl:px-10">
Expand All @@ -44,7 +44,6 @@ export const Footer: React.FC = () => {
<div className="flex">
<IconLink
href={
chainId &&
xvs &&
generateBscScanUrl({
hash: xvs.address,
Expand Down
13 changes: 5 additions & 8 deletions src/containers/ReadableActionSignature/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ export const ReadableActionSignatureUi: React.FC<ReadableActionSignatureUiProps>
<Typography css={styles.signature} className={className}>
<Typography
component="a"
href={
chainId &&
generateBscScanUrl({
hash: action.target,
urlType: 'address',
chainId,
})
}
href={generateBscScanUrl({
hash: action.target,
urlType: 'address',
chainId,
})}
target="_blank"
rel="noreferrer"
>
Expand Down
5 changes: 2 additions & 3 deletions src/context/AuthContext/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { openInfinityWallet } from '@infinitywallet/infinity-connector';
import config from 'config';
import { VError, logError } from 'errors';
import { Signer, getDefaultProvider } from 'ethers';
import noop from 'noop-ts';
Expand Down Expand Up @@ -46,8 +45,8 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
const { address, isConnected } = useAccount();
const { chain } = useNetwork();

// TODO: get from chain instead of config
const chainId = config.isOnTestnet ? ChainId.BSC_TESTNET : ChainId.BSC_MAINNET;
const defaultChainId = chains[0].id;
const chainId = chain?.id || defaultChainId;

const signer = useSigner();
const provider = useProvider();
Expand Down
15 changes: 10 additions & 5 deletions src/hooks/useGetSwapInfo/useGetTokenCombinations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export interface UseGetTokenCombinationsInput {
}

// List tokens to check trades against
const baseTradeTokenSymbols = {
[ChainId.BSC_MAINNET]: ['BUSD', 'ETH', 'XVS', 'WBNB'],
[ChainId.BSC_TESTNET]: ['WBNB', 'CAKE', 'BUSD', 'USDT', 'BTCB', 'ETH', 'USDC'],
};
const baseTradeTokenSymbols = new Map([
[ChainId.BSC_MAINNET, ['BUSD', 'ETH', 'XVS', 'WBNB']],
[ChainId.BSC_TESTNET, ['WBNB', 'CAKE', 'BUSD', 'USDT', 'BTCB', 'ETH', 'USDC']],
]);

const useGetTokenCombinations = ({
fromToken,
Expand All @@ -30,7 +30,12 @@ const useGetTokenCombinations = ({
});

const baseTradeTokens = useMemo(
() => swapTokens.filter(token => baseTradeTokenSymbols[chainId].includes(token.symbol)),
() =>
baseTradeTokenSymbols.has(chainId)
? swapTokens.filter(token =>
(baseTradeTokenSymbols.get(chainId) || []).includes(token.symbol),
)
: [],
[swapTokens, chainId],
);

Expand Down
4 changes: 4 additions & 0 deletions src/packages/contracts/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export const contracts: ContractConfig[] = [
address: {
[ChainId.BSC_MAINNET]: '0xd130B43062D875a4B7aF3f8fc036Bc6e9D3E1B3E',
[ChainId.BSC_TESTNET]: '0xd130B43062D875a4B7aF3f8fc036Bc6e9D3E1B3E',
[ChainId.ETHEREUM]: '0xd130B43062D875a4B7aF3f8fc036Bc6e9D3E1B3E',
[ChainId.SEPOLIA]: '0xd130B43062D875a4B7aF3f8fc036Bc6e9D3E1B3E',
},
},
{
Expand Down Expand Up @@ -278,6 +280,8 @@ export const contracts: ContractConfig[] = [
[isolatedPoolsMainnetDeployments.contracts.Comptroller_LiquidStakedBNB.address.toLowerCase()]:
isolatedPoolsMainnetDeployments.contracts.SwapRouter_LiquidStakedBNB.address,
},
[ChainId.ETHEREUM]: {},
[ChainId.SEPOLIA]: {},
},
},
];
2 changes: 2 additions & 0 deletions src/packages/tokens/infos/commonTokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ import { tokens as bscTestnetTokens } from './bscTestnet';
export const tokens: TokenMapping = {
[ChainId.BSC_MAINNET]: bscMainnetTokens,
[ChainId.BSC_TESTNET]: bscTestnetTokens,
[ChainId.SEPOLIA]: [], // TODO: add records (see VEN-2121)
[ChainId.ETHEREUM]: [], // TODO: add records (see VEN-2120)
};
3 changes: 3 additions & 0 deletions src/packages/tokens/infos/disabledTokenActions/ethereum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { DisabledTokenAction } from '../../types';

export const disabledTokenActions: DisabledTokenAction[] = [];
4 changes: 4 additions & 0 deletions src/packages/tokens/infos/disabledTokenActions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { ChainId } from 'types';
import { DisabledTokenActionMapping } from '../../types';
import { disabledTokenActions as bscMainnetDisabledTokenActions } from './bscMainnet';
import { disabledTokenActions as bscTestnetDisabledTokenActions } from './bscTestnet';
import { disabledTokenActions as ethereumDisabledTokenActions } from './ethereum';
import { disabledTokenActions as sepoliaDisabledTokenActions } from './sepolia';

const disabledTokenActions: DisabledTokenActionMapping = {
[ChainId.BSC_MAINNET]: bscMainnetDisabledTokenActions,
[ChainId.BSC_TESTNET]: bscTestnetDisabledTokenActions,
[ChainId.ETHEREUM]: ethereumDisabledTokenActions,
[ChainId.SEPOLIA]: sepoliaDisabledTokenActions,
};

export default disabledTokenActions;
3 changes: 3 additions & 0 deletions src/packages/tokens/infos/disabledTokenActions/sepolia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { DisabledTokenAction } from '../../types';

export const disabledTokenActions: DisabledTokenAction[] = [];
3 changes: 3 additions & 0 deletions src/packages/tokens/infos/pancakeSwapTokens/ethereum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Token } from 'types';

export const tokens: Token[] = [];
4 changes: 4 additions & 0 deletions src/packages/tokens/infos/pancakeSwapTokens/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import { ChainId } from 'types';
import { TokenMapping } from '../../types';
import { tokens as bscMainnetTokens } from './bscMainnet';
import { tokens as bscTestnetTokens } from './bscTestnet';
import { tokens as ethereumTokens } from './ethereum';
import { tokens as sepoliaTokens } from './sepolia';

export const pancakeSwapTokens: TokenMapping = {
[ChainId.BSC_MAINNET]: bscMainnetTokens,
[ChainId.BSC_TESTNET]: bscTestnetTokens,
[ChainId.ETHEREUM]: ethereumTokens,
[ChainId.SEPOLIA]: sepoliaTokens,
};
3 changes: 3 additions & 0 deletions src/packages/tokens/infos/pancakeSwapTokens/sepolia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Token } from 'types';

export const tokens: Token[] = [];
39 changes: 15 additions & 24 deletions src/pages/History/HistoryTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,11 @@ export const HistoryTableUi: React.FC<HistoryTableProps> = ({ transactions, isFe
selectOptionLabel: t('history.columns.hash'),
renderCell: transaction => (
<Link
href={
chainId &&
generateBscScanUrl({
hash: transaction.transactionHash,
urlType: 'tx',
chainId,
})
}
href={generateBscScanUrl({
hash: transaction.transactionHash,
urlType: 'tx',
chainId,
})}
className="text-blue"
>
<EllipseAddress address={transaction.transactionHash} />
Expand All @@ -112,14 +109,11 @@ export const HistoryTableUi: React.FC<HistoryTableProps> = ({ transactions, isFe
selectOptionLabel: t('history.columns.from'),
renderCell: transaction => (
<Link
href={
chainId &&
generateBscScanUrl({
hash: transaction.from,
urlType: 'address',
chainId,
})
}
href={generateBscScanUrl({
hash: transaction.from,
urlType: 'address',
chainId,
})}
className="text-blue"
>
<EllipseAddress address={transaction.from} />
Expand All @@ -133,14 +127,11 @@ export const HistoryTableUi: React.FC<HistoryTableProps> = ({ transactions, isFe
renderCell: transaction =>
transaction.to ? (
<Link
href={
chainId &&
generateBscScanUrl({
hash: transaction.to,
urlType: 'address',
chainId,
})
}
href={generateBscScanUrl({
hash: transaction.to,
urlType: 'address',
chainId,
})}
className="text-blue"
>
<EllipseAddress address={transaction.to} />
Expand Down
13 changes: 5 additions & 8 deletions src/pages/Voter/Transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,11 @@ export const Transactions: React.FC<TransactionsProps> = ({
asChild
>
<Link
href={
chainId &&
generateBscScanUrl({
hash: address,
urlType: 'address',
chainId,
})
}
href={generateBscScanUrl({
hash: address,
urlType: 'address',
chainId,
})}
>
{t('voterDetail.viewAll')}
</Link>
Expand Down
Loading

0 comments on commit 911d245

Please sign in to comment.