Skip to content

Commit

Permalink
feat(pg): Add support for Base
Browse files Browse the repository at this point in the history
  • Loading branch information
RPate97 committed Aug 14, 2023
1 parent 7700885 commit 7ed7d07
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/olive-mayflies-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sphinx-labs/plugins': patch
'@sphinx-labs/core': patch
---

Add support for Base
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ You can also use Sphinx's Hardhat or Foundry plugin as a feature-limited deploym
- Avalanche C-Chain
- Linea
- Fantom
- Base

Test networks:

Expand All @@ -70,6 +71,7 @@ Test networks:
- Avalanche Fuji
- Linea Goerli
- Fantom Testnet
- Base Goerli

More networks are on the way! Please feel free to reach out in our [Discord](https://discord.gg/7Gc3DK33Np) if there are networks you'd like us to add.

Expand Down
10 changes: 10 additions & 0 deletions packages/core/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ const config: HardhatUserConfig = {
url: `https://avalanche-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts,
},
base: {
chainId: 8453,
url: `${process.env.BASE_MAINNET_URL}`,
accounts,
},
'base-goerli': {
chainId: 84531,
url: `${process.env.BASE_GOERLI_URL}`,
accounts,
},
},
}

Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ export const customChains: CustomChain[] = [
browserURL: 'https://zkevm.polygonscan.com',
},
},
{
network: 'base',
chainId: 8453,
urls: {
apiURL: 'https://api.basescan.org/api',
browserURL: 'https://basescan.org/',
},
},
{
network: 'base-goerli',
chainId: 84531,
urls: {
apiURL: 'https://api-goerli.basescan.org/api',
browserURL: 'https://goerli.basescan.org/',
},
},
]

export const EXECUTION_BUFFER_MULTIPLIER = 2
Expand Down
204 changes: 204 additions & 0 deletions packages/core/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type SupportedMainnetNetworkName =
| 'polygon-zkevm'
| 'avalanche'
| 'fantom'
| 'base'
type SupportedTestnetNetworkName =
| 'goerli'
| 'optimism-goerli'
Expand All @@ -24,6 +25,7 @@ type SupportedTestnetNetworkName =
| 'polygon-zkevm-goerli'
| 'avalanche-fuji'
| 'fantom-testnet'
| 'base-goerli'

export type SupportedNetworkName =
| SupportedMainnetNetworkName
Expand All @@ -44,6 +46,7 @@ export const SUPPORTED_MAINNETS: Record<
'polygon-zkevm': 1101,
avalanche: 43114,
fantom: 250,
base: 8453,
}
export const SUPPORTED_TESTNETS: Record<
SupportedTestnetNetworkName,
Expand All @@ -59,6 +62,7 @@ export const SUPPORTED_TESTNETS: Record<
'polygon-zkevm-goerli': 1442,
'avalanche-fuji': 43113,
'fantom-testnet': 4002,
'base-goerli': 84531,
}
export const SUPPORTED_NETWORKS = {
...SUPPORTED_MAINNETS,
Expand All @@ -80,6 +84,7 @@ export type SupportedMainnetChainId =
| 1101
| 43114
| 250
| 8453
export type SupportedTestnetChainId =
| 5
| 420
Expand All @@ -91,12 +96,211 @@ export type SupportedTestnetChainId =
| 1442
| 43113
| 4002
| 84531
export type SupportedChainId = SupportedMainnetChainId | SupportedTestnetChainId

export const MinimumWalletBalanceTestnets = {
goerli: '0.15',
'optimism-goerli': '0.15',
'arbitrum-goerli': '0.15',
bnbt: '0.15',
maticmum: '0.15',
'gnosis-chiado': '0.15',
'linea-goerli': '0.15',
'polygon-zkevm-goerli': '0.15',
'avalanche-fuji': '1',
'fantom-testnet': '1',
'base-goerli': '0.15',
}

export const MinimumWalletBalanceMainnets = {
ethereum: '.05',
optimism: '.025',
arbitrum: '.025',
matic: '1',
bnb: '.05',
xdai: '1',
linea: '0.025',
'polygon-zkevm': '0.025',
avalanche: '1',
fantom: '1',
base: '0.025',
}

export const MinimumWalletBalance = {
...MinimumWalletBalanceTestnets,
...MinimumWalletBalanceMainnets,
}

// Maps a chain ID to the USDC address on the network.
export const USDC_ADDRESSES: { [chainId: string]: string } = {
// Optimism Goerli:
420: '0x7E07E15D2a87A24492740D16f5bdF58c16db0c4E',
// Optimism Mainnet:
10: '0x7F5c764cBc14f9669B88837ca1490cCa17c31607',
}

export const fetchCurrencyForNetwork = (chainId: number) => {
switch (chainId) {
// mainnet
case 1:
return 'ETH'
// goerli
case 5:
return 'ETH'
// optimism
case 10:
return 'ETH'
// optimism goerli
case 420:
return 'ETH'
// arbitrum
case 42161:
return 'ETH'
// arbitrum goerli
case 421613:
return 'ETH'
// BNB
case 56:
return 'BNB'
// BNB testnet
case 97:
return 'BNB'
// Gnosis
case 100:
return 'xDAI'
// Chiado
case 10200:
return 'xDAI'
// Polygon
case 137:
return 'MATIC'
// Polygon Mumbai
case 80001:
return 'MATIC'
// Polygon zkEVM Testnet
case 1101:
return 'ETH'
// Polygon zkEVM Mainnet
case 1442:
return 'ETH'
// Linea Mainnet
case 59144:
return 'ETH'
// Linea Testnet
case 59140:
return 'ETH'
case 4002:
return 'FTM'
case 250:
return 'FTM'
case 43113:
return 'AVAX'
case 43114:
return 'AVAX'
case 8453:
return 'ETH'
case 84531:
return 'ETH'
default:
throw new Error('Unsupported network')
}
}

export const fetchURLForNetwork = (chainId: number) => {
if (process.env.RUNNING_LOCALLY === 'true') {
return `http://127.0.0.1:${42000 + (chainId % 1000)}`
}

if (!process.env.ALCHEMY_API_KEY) {
throw new Error('ALCHEMY_API_KEY key not defined')
}
if (!process.env.BNB_TESTNET_URL) {
throw new Error('BNB_TESTNET_URL key not defined')
}
if (!process.env.BNB_MAINNET_URL) {
throw new Error('BNB_MAINNET_URL key not defined')
}
if (!process.env.CHIADO_RPC_URL) {
throw new Error('CHIADO_RPC_URL key not defined')
}
if (!process.env.GNOSIS_MAINNET_URL) {
throw new Error('GNOSIS_MAINNET_URL key not defined')
}
if (!process.env.POLYGON_ZKEVM_MAINNET_URL) {
throw new Error('POLYGON_ZKEVM_MAINNET_URL key not defined')
}
if (!process.env.POLYGON_ZKEVM_TESTNET_URL) {
throw new Error('POLYGON_ZKEVM_TESTNET_URL key not defined')
}
if (!process.env.FANTOM_TESTNET_RPC_URL) {
throw new Error('FANTOM_TESTNET_RPC_URL key not defined')
}
if (!process.env.FANTOM_MAINNET_RPC_URL) {
throw new Error('FANTOM_MAINNET_RPC_URL key not defined')
}
if (!process.env.BASE_MAINNET_URL) {
throw new Error('BASE_MAINNET_URL key not defined')
}
if (!process.env.BASE_GOERLI_URL) {
throw new Error('BASE_GOERLI_URL key not defined')
}

switch (chainId) {
// mainnet
case 1:
return `https://eth-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
// goerli
case 5:
return `https://eth-goerli.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
// optimism
case 10:
return `https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
// optimism goerli
case 420:
return `https://opt-goerli.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
// arbitrum goerli
case 421613:
return `https://arb-goerli.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
// arbitrum mainnet
case 42161:
return `https://arb-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
// bnbt
case 97:
return process.env.BNB_TESTNET_URL
case 56:
return process.env.BNB_MAINNET_URL
// gnosis chiado
case 10200:
return process.env.CHIADO_RPC_URL
case 100:
return process.env.GNOSIS_MAINNET_URL
// polygon mumbai
case 80001:
return `https://polygon-mumbai.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
case 137:
return `https://polygon-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
case 1101:
return process.env.POLYGON_ZKEVM_MAINNET_URL
case 1442:
return process.env.POLYGON_ZKEVM_TESTNET_URL
case 59144:
return `https://linea-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`
case 59140:
return `https://linea-goerli.infura.io/v3/${process.env.INFURA_API_KEY}`
case 4002:
return process.env.FANTOM_TESTNET_RPC_URL
case 250:
return process.env.FANTOM_MAINNET_RPC_URL
case 43113:
return `https://avalanche-fuji.infura.io/v3/${process.env.INFURA_API_KEY}`
case 43114:
return `https://avalanche-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`
case 8453:
return process.env.BASE_MAINNET_URL
case 84531:
return process.env.BASE_GOERLI_URL
default:
throw new Error(`Unsupported chain for id ${chainId}`)
}
}
10 changes: 10 additions & 0 deletions packages/plugins/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ const config: HardhatUserConfig = {
// url: `https://avalanche-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
// accounts,
// },
// base: {
// chainId: 8453,
// url: `${process.env.BASE_MAINNET_URL}`,
// accounts,
// },
// 'base-goerli': {
// chainId: 84531,
// url: `${process.env.BASE_GOERLI_URL}`,
// accounts,
// },

goerli: {
chainId: 5,
Expand Down

0 comments on commit 7ed7d07

Please sign in to comment.