Skip to content

Commit

Permalink
feat: apechain support (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSinclair authored Oct 19, 2024
1 parent 187af0e commit 3f6c598
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 38 deletions.
50 changes: 18 additions & 32 deletions lavamoat/build-webpack/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,10 @@
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/helper-module-transforms>@babel/helper-module-imports": true,
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/helper-module-transforms>@babel/helper-simple-access": true,
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/helper-module-transforms>@babel/helper-split-export-declaration": true,
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/helper-module-transforms>@babel/helper-validator-identifier": true,
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/template": true,
"jest>@jest/core>jest-snapshot>@babel/traverse": true,
"jest>@jest/core>jest-snapshot>@babel/types": true,
"jest>@jest/core>jest-snapshot>@babel/types>@babel/helper-validator-identifier": true
"jest>@jest/core>jest-snapshot>@babel/types": true
}
},
"eslint-config-rainbow>eslint-import-resolver-babel-module>@babel/core>@babel/helper-module-transforms>@babel/helper-module-imports": {
Expand Down Expand Up @@ -1141,9 +1141,16 @@
"console.warn": true,
"process.emitWarning": true
},
"packages": {
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/code-frame>@babel/highlight": true,
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/code-frame>chalk": true
}
},
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/code-frame>@babel/highlight": {
"packages": {
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/code-frame>chalk": true,
"lavamoat>@babel/highlight": true
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/types>@babel/helper-validator-identifier": true,
"react>loose-envify>js-tokens": true
}
},
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/code-frame>chalk": {
Expand Down Expand Up @@ -1217,34 +1224,6 @@
"lavamoat>lavamoat-core>@babel/types>to-fast-properties": true
}
},
"lavamoat>@babel/highlight": {
"packages": {
"lavamoat>@babel/highlight>@babel/helper-validator-identifier": true,
"lavamoat>@babel/highlight>chalk": true,
"react>loose-envify>js-tokens": true
}
},
"lavamoat>@babel/highlight>chalk": {
"globals": {
"process.env.TERM": true,
"process.platform": true
},
"packages": {
"lavamoat>@babel/highlight>chalk>ansi-styles": true,
"lavamoat>@babel/highlight>chalk>escape-string-regexp": true,
"supports-color": true
}
},
"lavamoat>@babel/highlight>chalk>ansi-styles": {
"packages": {
"lavamoat>@babel/highlight>chalk>ansi-styles>color-convert": true
}
},
"lavamoat>@babel/highlight>chalk>ansi-styles>color-convert": {
"packages": {
"lavamoat>@babel/highlight>chalk>ansi-styles>color-convert>color-name": true
}
},
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name": {
"packages": {
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template": true,
Expand All @@ -1264,10 +1243,17 @@
"process.emitWarning": true
},
"packages": {
"lavamoat>@babel/highlight": true,
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template>@babel/code-frame>@babel/highlight": true,
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template>@babel/code-frame>chalk": true
}
},
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template>@babel/code-frame>@babel/highlight": {
"packages": {
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template>@babel/code-frame>chalk": true,
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/types>@babel/helper-validator-identifier": true,
"react>loose-envify>js-tokens": true
}
},
"lavamoat>lavamoat-tofu>@babel/traverse>@babel/helper-function-name>@babel/template>@babel/code-frame>chalk": {
"globals": {
"process.env.TERM": true,
Expand Down
2 changes: 2 additions & 0 deletions src/core/firebase/remoteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface RainbowConfig extends Record<string, any> {
[ChainName.avalanche]: number;
[ChainName.blast]: number;
[ChainName.degen]: number;
[ChainName.apechain]: number;
};
}

Expand Down Expand Up @@ -69,6 +70,7 @@ const DEFAULT_CONFIG = {
avalanche: 200,
blast: 200,
degen: 200,
apechain: 200,
},
};

Expand Down
3 changes: 3 additions & 0 deletions src/core/references/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
coreDao,
cronos,
cronosTestnet,
curtis,
degen,
dogechain,
fantom,
Expand Down Expand Up @@ -76,6 +77,8 @@ import {
import { ChainId } from '../types/chains';

export const customChainIdsToAssetNames: Record<ChainId, string> = {
33139: 'apechain',
[curtis.id]: 'apechaincurtis',
[arbitrumNova.id]: 'arbitrumnova',
[aurora.id]: 'aurora',
[auroraTestnet.id]: 'auroratestnet',
Expand Down
12 changes: 12 additions & 0 deletions src/core/references/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export const POL_MAINNET_ADDRESS = '0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6';
export const BNB_MAINNET_ADDRESS = '0xb8c77482e45f1f44de1745f52c74426c631bdd52';
export const SOCKS_ADDRESS = '0x23b608675a2b2fb1890d3abbd85c5775c51691d5';
export const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
export const APECOIN_MAINNET_ADDRESS =
'0x4d224452801aced8b2f0aebe155379bb5d594381';

// arbitrum
export const APECOIN_ARBITRUM_ADDRESS =
'0x7f9FBf9bDd3F4105C478b996B648FE6e828a1e98';

// optimism
export const ETH_OPTIMISM_ADDRESS = AddressZero;
Expand Down Expand Up @@ -120,6 +126,12 @@ export const USDB_BLAST_ADDRESS = '0x4300000000000000000000000000000000000003';
// degen
export const DEGEN_DEGEN_ADDRESS = AddressZero;

// apechain
export const APE_APECHAIN_ADDRESS = AddressZero;
export const WAPE_APECHAIN_ADDRESS = '0x48b62137edfa95a428d35c09e44256a739f6b557';
export const APEETH_APECHAIN_ADDRESS = '0xcF800F4948D16F23333508191B1B1591daF70438';
export const APEUSD_APECHAIN_ADDRESS = '0xA2235d059F80e176D931Ef76b6C51953Eb3fBEf4';

export const OVM_GAS_PRICE_ORACLE =
'0x420000000000000000000000000000000000000F';

Expand Down
15 changes: 14 additions & 1 deletion src/core/state/favorites/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import create from 'zustand';

import {
APE_APECHAIN_ADDRESS,
APEETH_APECHAIN_ADDRESS,
APEUSD_APECHAIN_ADDRESS,
AVAX_AVALANCHE_ADDRESS,
BNB_BSC_ADDRESS,
DAI_ADDRESS,
Expand Down Expand Up @@ -29,6 +32,7 @@ import {
USDC_BSC_ADDRESS,
USDC_OPTIMISM_ADDRESS,
USDC_POLYGON_ADDRESS,
WAPE_APECHAIN_ADDRESS,
WAVAX_AVALANCHE_ADDRESS,
WBTC_ADDRESS,
WBTC_ARBITRUM_ADDRESS,
Expand Down Expand Up @@ -107,6 +111,12 @@ const defaultFavorites = {
],
[ChainId.blast]: [ETH_BLAST_ADDRESS, WETH_BLAST_ADDRESS, USDB_BLAST_ADDRESS],
[ChainId.degen]: [DEGEN_DEGEN_ADDRESS],
[ChainId.apechain]: [
APE_APECHAIN_ADDRESS,
WAPE_APECHAIN_ADDRESS,
APEETH_APECHAIN_ADDRESS,
APEUSD_APECHAIN_ADDRESS,
],
} satisfies FavoritesState['favorites'];

const mergeNewOfficiallySupportedChainsState = (
Expand Down Expand Up @@ -151,7 +161,7 @@ export const favoritesStore = createStore<FavoritesState>(
{
persist: persistOptions({
name: 'favorites',
version: 4,
version: 5,
migrations: [
// version 1 didn't need a migration
(state: FavoritesState) => state,
Expand All @@ -164,6 +174,9 @@ export const favoritesStore = createStore<FavoritesState>(
// version 4 added degen
(state) =>
mergeNewOfficiallySupportedChainsState(state, [ChainId.degen]),
// version 5 added apechain
(state) =>
mergeNewOfficiallySupportedChainsState(state, [ChainId.apechain]),
],
}),
},
Expand Down
8 changes: 8 additions & 0 deletions src/core/types/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const chainHardhatOptimism: Chain = {
};

export enum ChainName {
apechain = 'apechain',
apechainCurtis = 'apechain-curtis',
arbitrum = 'arbitrum',
arbitrumNova = 'arbitrum-nova',
arbitrumSepolia = 'arbitrum-sepolia',
Expand Down Expand Up @@ -84,6 +86,8 @@ export enum ChainName {
}

export enum ChainId {
apechain = 33139,
apechainCurtis = chains.curtis.id,
arbitrum = chains.arbitrum.id,
arbitrumNova = chains.arbitrumNova.id,
arbitrumSepolia = chains.arbitrumSepolia.id,
Expand Down Expand Up @@ -137,6 +141,8 @@ export const chainNameToIdMapping: {
} = {
['ethereum']: ChainId.mainnet,
['ethereum-sepolia']: ChainId.sepolia,
[ChainName.apechain]: ChainId.apechain,
[ChainName.apechainCurtis]: ChainId.apechainCurtis,
[ChainName.arbitrum]: ChainId.arbitrum,
[ChainName.arbitrumNova]: ChainId.arbitrumNova,
[ChainName.arbitrumSepolia]: ChainId.arbitrumSepolia,
Expand Down Expand Up @@ -188,6 +194,8 @@ export const chainNameToIdMapping: {
export const chainIdToNameMapping: {
[key in ChainId]: ChainName;
} = {
[ChainId.apechain]: ChainName.apechain,
[ChainId.apechainCurtis]: ChainName.apechainCurtis,
[ChainId.arbitrum]: ChainName.arbitrum,
[ChainId.arbitrumNova]: ChainName.arbitrumNova,
[ChainId.arbitrumSepolia]: ChainName.arbitrumSepolia,
Expand Down
1 change: 1 addition & 0 deletions src/core/types/nfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface PolygonAllowListDictionary {
export enum SimpleHashChain {
AlignTestnet = 'align-testnet',
AnomalyAndromedaTestnet = 'anomaly-andromeda-testnet',
Apechain = 'apechain',
Arbitrum = 'arbitrum',
ArbitrumNova = 'arbitrum-nova',
ArbitrumSepolia = 'arbitrum-sepolia',
Expand Down
1 change: 1 addition & 0 deletions src/core/utils/faucets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const TestnetFaucet = {
[ChainId.avalancheFuji]: 'https://faucet.quicknode.com/avalanche/fuji',
[ChainId.blastSepolia]: 'https://faucet.quicknode.com/blast/sepolia',
[ChainId.polygonAmoy]: 'https://faucet.polygon.technology',
[ChainId.apechainCurtis]: 'https://curtis.hub.caldera.xyz/',
[celoAlfajores.id]: 'https://faucet.celo.org/alfajores',
[fantomTestnet.id]: 'https://faucet.fantom.network',
[filecoinCalibration.id]: 'https://beryx.io/faucet',
Expand Down
3 changes: 3 additions & 0 deletions src/core/utils/nfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const ENS_NFT_CONTRACT_ADDRESS =

export const simpleHashSupportedChainNames = [
'ethereum',
ChainName.apechain,
ChainName.arbitrum,
ChainName.arbitrumNova,
ChainName.avalanche,
Expand Down Expand Up @@ -91,6 +92,8 @@ export function getNetworkFromSimpleHashChain(
chain: SimpleHashChain,
): ChainName {
switch (chain) {
case SimpleHashChain.Apechain:
return ChainName.apechain;
case SimpleHashChain.Avalanche:
return ChainName.avalanche;
case SimpleHashChain.AvalancheFuji:
Expand Down
9 changes: 7 additions & 2 deletions src/core/utils/userChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
blastSepolia,
bsc,
bscTestnet,
curtis,
degen,
holesky,
mainnet,
Expand Down Expand Up @@ -37,7 +38,8 @@ export const chainIdMap: Record<
| ChainId.zora
| ChainId.avalanche
| ChainId.blast
| ChainId.degen,
| ChainId.degen
| ChainId.apechain,
ChainId[]
> = {
[ChainId.mainnet]: [mainnet.id, sepolia.id, holesky.id],
Expand All @@ -50,6 +52,7 @@ export const chainIdMap: Record<
[ChainId.avalanche]: [avalanche.id, avalancheFuji.id],
[ChainId.blast]: [blast.id, blastSepolia.id],
[ChainId.degen]: [degen.id],
[ChainId.apechain]: [ChainId.apechain, curtis.id],
};

export const chainLabelMap: Record<
Expand All @@ -61,7 +64,8 @@ export const chainLabelMap: Record<
| ChainId.zora
| ChainId.avalanche
| ChainId.blast
| ChainId.degen,
| ChainId.degen
| ChainId.apechain,
string[]
> = {
[ChainId.mainnet]: [chainsLabel[sepolia.id], chainsLabel[holesky.id]],
Expand All @@ -74,6 +78,7 @@ export const chainLabelMap: Record<
[ChainId.avalanche]: [chainsLabel[avalancheFuji.id]],
[ChainId.blast]: [chainsLabel[blastSepolia.id]],
[ChainId.degen]: [],
[ChainId.apechain]: [chainsLabel[curtis.id]],
};

export const sortNetworks = (order: ChainId[], chains: Chain[]) => {
Expand Down
2 changes: 2 additions & 0 deletions src/entries/iframe/notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const ASSET_SOURCE = {
[ChainId.avalancheFuji]: 'assets/badges/[email protected]',
[ChainId.blast]: 'assets/badges/[email protected]',
[ChainId.blastSepolia]: 'assets/badges/[email protected]',
[ChainId.apechain]: 'assets/badges/[email protected]',
[ChainId.apechainCurtis]: 'assets/badges/[email protected]',
};

export enum IN_DAPP_NOTIFICATION_STATUS {
Expand Down
3 changes: 3 additions & 0 deletions src/entries/popup/components/ChainBadge/ChainBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AddressZero } from '@ethersproject/constants';

import ApeChainBadge from 'static/assets/badges/[email protected]';
import ArbitrumBadge from 'static/assets/badges/[email protected]';
import AvalancheBadge from 'static/assets/badges/[email protected]';
import BaseBadge from 'static/assets/badges/[email protected]';
Expand Down Expand Up @@ -62,6 +63,8 @@ const networkBadges = {
[ChainId.blast]: BlastBadge,
[ChainId.blastSepolia]: BlastBadge,
[ChainId.degen]: DegenBadge,
[ChainId.apechain]: ApeChainBadge,
[ChainId.apechainCurtis]: ApeChainBadge,
};

const ChainBadge = ({
Expand Down
1 change: 1 addition & 0 deletions src/entries/popup/components/SideChainExplainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const getSideChainExplainerParams = (
[ChainId.avalanche]: 'avalanche',
[ChainId.blast]: 'blast',
[ChainId.degen]: 'degen',
[ChainId.apechain]: 'apechain',
// add new chains here with unique i18n explainer keys
};

Expand Down
5 changes: 4 additions & 1 deletion src/entries/popup/hooks/swap/useSwapSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const DEFAULT_SLIPPAGE_BIPS = {
[ChainId.avalanche]: 200,
[ChainId.blast]: 200,
[ChainId.degen]: 200,
[ChainId.apechain]: 200,
};

export const DEFAULT_SLIPPAGE = {
Expand All @@ -31,6 +32,7 @@ export const DEFAULT_SLIPPAGE = {
[ChainId.avalanche]: '2',
[ChainId.blast]: '2',
[ChainId.degen]: '2',
[ChainId.apechain]: '2',
};

const slippageInBipsToString = (slippageInBips: number) =>
Expand All @@ -47,7 +49,8 @@ export const getDefaultSlippage = (chainId: ChainId) => {
| ChainName.bsc
| ChainName.avalanche
| ChainName.blast
| ChainName.degen;
| ChainName.degen
| ChainName.apechain;
return slippageInBipsToString(
config.default_slippage_bips[chainName] || DEFAULT_SLIPPAGE_BIPS[chainId],
);
Expand Down
Loading

0 comments on commit 3f6c598

Please sign in to comment.