Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Optimism Sepolia chain support #123

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/constants/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum CHAINS {
Fuji = 43113,
Avalanche = 43114,
Sepolia = 11155111,
OptimismSepolia = 11155420,
}

export const CHAINS_IDS = [
Expand All @@ -27,6 +28,7 @@ export const CHAINS_IDS = [
CHAINS.Goerli,
CHAINS.Kovan,
CHAINS.Sepolia,
CHAINS.OptimismSepolia,
];

export const CHAINS_COLORS: {
Expand All @@ -39,6 +41,7 @@ export const CHAINS_COLORS: {
[CHAINS.Holesky]: '#AA346A',
[CHAINS.Kovan]: '#9064ff',
[CHAINS.Sepolia]: '#FFD700',
[CHAINS.OptimismSepolia]: '#FF8C00',
};

export const getChainColor = (chainId: CHAINS): string => {
Expand Down
33 changes: 32 additions & 1 deletion packages/constants/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ export const TOKENS_BY_NETWORK: {
},
};

export const getTokenAddress = (chainId: CHAINS, token: TOKENS): string => {
export const L2_TOKENS_BY_NETWORK: {
[key in CHAINS]?: { [key in TOKENS]?: string };
} = {
[CHAINS.OptimismSepolia]: {
[TOKENS.WSTETH]: '0x24B47cd3A74f1799b32B2de11073764Cb1bb318B',
[TOKENS.STETH]: '0xf49d208b5c7b10415c7beafe9e656f2df9edfe3b',
},
};

export const getL1TokenAddress = (chainId: CHAINS, token: TOKENS): string => {
const tokens = TOKENS_BY_NETWORK[chainId];
invariant(tokens, 'Chain is not supported');

Expand All @@ -49,3 +58,25 @@ export const getTokenAddress = (chainId: CHAINS, token: TOKENS): string => {

return address;
};

export const getL2TokenAddress = (chainId: CHAINS, token: TOKENS): string => {
const tokens = L2_TOKENS_BY_NETWORK[chainId];
invariant(tokens, 'L2 chain is not supported');

const address = tokens[token];
invariant(address, 'L2 token is not supported');

return address;
};

export const getTokenAddress = (chainId: CHAINS, token: TOKENS): string => {
if (token === TOKENS.LDO) {
const _chainId =
chainId === CHAINS.OptimismSepolia ? CHAINS.Sepolia : chainId;
return getL1TokenAddress(_chainId, token);
} else {
return chainId === CHAINS.OptimismSepolia
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are going to have here multiple chains. Optimism and then possibly other l2. So let's adopt a solution to match multple l2 networks.

? getL2TokenAddress(chainId, token)
: getL1TokenAddress(chainId, token);
}
};
4 changes: 4 additions & 0 deletions packages/fetch/src/providersUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const getInfuraRPCUrl = (chainId: CHAINS, apiKey: string): string => {
return `https://holesky.infura.io/v3/${apiKey}`;
case CHAINS.Sepolia:
return `https://sepolia.infura.io/v3/${apiKey}`;
case CHAINS.OptimismSepolia:
return `https://optimism-sepolia.infura.io/v3/${apiKey}`;
default:
invariant(false, 'Chain is not supported');
}
Expand All @@ -42,6 +44,8 @@ export const getAlchemyRPCUrl = (chainId: CHAINS, apiKey: string): string => {
return `https://eth-holesky.alchemyapi.io/v2/${apiKey}`;
case CHAINS.Sepolia:
return `https://eth-sepolia.g.alchemy.com/v2/${apiKey}`;
case CHAINS.OptimismSepolia:
return `https://opt-sepolia.g.alchemy.com/v2/${apiKey}`;
default:
invariant(false, 'Chain is not supported');
}
Expand Down
1 change: 1 addition & 0 deletions packages/helpers/src/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const ETHERSCAN_PREFIX_BY_NETWORK: {
[CHAINS.Kovan]: 'kovan.',
[CHAINS.Holesky]: 'holesky.',
[CHAINS.Sepolia]: 'sepolia.',
[CHAINS.OptimismSepolia]: 'sepolia-optimistic.',
};

export const getEtherscanPrefix = (chainId: CHAINS): string => {
Expand Down
Loading