-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new configs folder structure (#54)
* add new folder structure * fix prettier * apply suggestions * fix prettier * fix imports
- Loading branch information
1 parent
1cf46ff
commit 3ac6c88
Showing
21 changed files
with
237 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {SupportedNetworks} from '../networks'; | ||
import * as arbitrum from './json/arbitrum.json'; | ||
import * as arbitrumSepolia from './json/arbitrumSepolia.json'; | ||
import * as baseGoerli from './json/baseGoerli.json'; | ||
import * as baseMainnet from './json/baseMainnet.json'; | ||
import * as baseSepolia from './json/baseSepolia.json'; | ||
import * as goerli from './json/goerli.json'; | ||
import * as mainnet from './json/mainnet.json'; | ||
import * as mumbai from './json/mumbai.json'; | ||
import * as polygon from './json/polygon.json'; | ||
import * as sepolia from './json/sepolia.json'; | ||
import {NetworkDeployment, SupportedVersions} from './types'; | ||
|
||
export { | ||
mainnet, | ||
goerli, | ||
sepolia, | ||
polygon, | ||
mumbai, | ||
baseMainnet, | ||
baseGoerli, | ||
baseSepolia, | ||
arbitrum, | ||
arbitrumSepolia, | ||
}; | ||
|
||
export const contracts: { | ||
[network in SupportedNetworks]: { | ||
[version in SupportedVersions]?: NetworkDeployment; | ||
}; | ||
} = { | ||
mainnet, | ||
goerli, | ||
sepolia, | ||
polygon, | ||
mumbai, | ||
baseMainnet, | ||
baseGoerli, | ||
baseSepolia, | ||
arbitrum, | ||
arbitrumSepolia, | ||
local: { | ||
[SupportedVersions.V1_0_0]: {} as NetworkDeployment, | ||
[SupportedVersions.V1_3_0]: {} as NetworkDeployment, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {SupportedNetworks} from '../networks'; | ||
import {contracts} from './contracts'; | ||
import { | ||
NetworkDeployment, | ||
NetworkDeployments, | ||
SupportedVersions, | ||
} from './types'; | ||
|
||
/** | ||
* Retrieves the network deployments based on the specified network. | ||
* | ||
* @param {SupportedNetworks} network - The network to retrieve the deployments for. | ||
* @return {NetworkDeployments} The network deployments for the specified network. | ||
*/ | ||
export function getNetworkDeployments( | ||
network: SupportedNetworks | ||
): NetworkDeployments { | ||
return contracts[network]; | ||
} | ||
|
||
/** | ||
* Retrieves the network deployment for a specific version. | ||
* | ||
* @param {SupportedNetworks} network - The network to retrieve the deployment for. | ||
* @param {SupportedVersions} version - The version of the deployment. | ||
* @return {NetworkDeployment | null} The network deployment for the specified version, or null if not found. | ||
*/ | ||
export function getNetworkDeploymentForVersion( | ||
network: SupportedNetworks, | ||
version: SupportedVersions | ||
): NetworkDeployment | null { | ||
return getNetworkDeployments(network)[version] || null; | ||
} | ||
|
||
/** | ||
* Retrieves the latest network deployment for the specified network. | ||
* | ||
* @param {SupportedNetworks} network - The network to retrieve the deployment for. | ||
* @return {NetworkDeployment | null} The latest network deployment, or null if not found. | ||
*/ | ||
export function getLatestNetworkDeployment( | ||
network: SupportedNetworks | ||
): NetworkDeployment | null { | ||
const versions = Object.values(SupportedVersions).reverse(); | ||
for (const version of versions) { | ||
const deployment = getNetworkDeploymentForVersion(network, version); | ||
if (deployment) { | ||
return deployment; | ||
} | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,3 @@ | ||
import { | ||
NetworkDeployment, | ||
NetworkDeployments, | ||
SupportedNetworks, | ||
SupportedVersions, | ||
} from '../types'; | ||
import * as arbitrum from './arbitrum.json'; | ||
import * as arbitrumSepolia from './arbitrumSepolia.json'; | ||
import * as baseGoerli from './baseGoerli.json'; | ||
import * as baseMainnet from './baseMainnet.json'; | ||
import * as baseSepolia from './baseSepolia.json'; | ||
import * as goerli from './goerli.json'; | ||
import * as mainnet from './mainnet.json'; | ||
import * as mumbai from './mumbai.json'; | ||
import * as polygon from './polygon.json'; | ||
import * as sepolia from './sepolia.json'; | ||
|
||
const contracts: { | ||
[network in SupportedNetworks]: { | ||
[version in SupportedVersions]?: NetworkDeployment; | ||
}; | ||
} = { | ||
mainnet, | ||
goerli, | ||
sepolia, | ||
polygon, | ||
mumbai, | ||
baseMainnet, | ||
baseGoerli, | ||
baseSepolia, | ||
arbitrum, | ||
arbitrumSepolia, | ||
local: { | ||
[SupportedVersions.V1_0_0]: {} as NetworkDeployment, | ||
[SupportedVersions.V1_3_0]: {} as NetworkDeployment, | ||
}, | ||
}; | ||
|
||
/** | ||
* Retrieves the network deployments based on the specified network. | ||
* | ||
* @param {SupportedNetworks} network - The network to retrieve the deployments for. | ||
* @return {NetworkDeployments} The network deployments for the specified network. | ||
*/ | ||
export function getNetworkDeployments( | ||
network: SupportedNetworks | ||
): NetworkDeployments { | ||
return contracts[network]; | ||
} | ||
|
||
/** | ||
* Retrieves the network deployment for a specific version. | ||
* | ||
* @param {SupportedNetworks} network - The network to retrieve the deployment for. | ||
* @param {SupportedVersions} version - The version of the deployment. | ||
* @return {NetworkDeployment | null} The network deployment for the specified version, or null if not found. | ||
*/ | ||
export function getNetworkDeploymentForVersion( | ||
network: SupportedNetworks, | ||
version: SupportedVersions | ||
): NetworkDeployment | null { | ||
return getNetworkDeployments(network)[version] || null; | ||
} | ||
|
||
/** | ||
* Retrieves the latest network deployment for the specified network. | ||
* | ||
* @param {SupportedNetworks} network - The network to retrieve the deployment for. | ||
* @return {NetworkDeployment | null} The latest network deployment, or null if not found. | ||
*/ | ||
export function getLatestNetworkDeployment( | ||
network: SupportedNetworks | ||
): NetworkDeployment | null { | ||
const versions = Object.values(SupportedVersions).reverse(); | ||
for (const version of versions) { | ||
const deployment = getNetworkDeploymentForVersion(network, version); | ||
if (deployment) { | ||
return deployment; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
export { | ||
contracts, | ||
mainnet, | ||
goerli, | ||
sepolia, | ||
polygon, | ||
mumbai, | ||
baseMainnet, | ||
baseGoerli, | ||
baseSepolia, | ||
arbitrum, | ||
arbitrumSepolia, | ||
}; | ||
export * from './types'; | ||
export * from './getters'; | ||
export * from './contracts'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './networks'; | ||
export * from './types'; | ||
export * from './deployments/index'; | ||
export * from './deployments'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import {networks} from './networks'; | ||
import {NetworkConfig, SupportedAliases, SupportedNetworks} from './types'; | ||
|
||
/** | ||
* Retrieves the network configuration for a given supported network. | ||
* | ||
* @param {SupportedNetworks} network - The supported network to retrieve the configuration for. | ||
* @return {NetworkConfig | null} The network configuration if it exists, otherwise null. | ||
*/ | ||
export function getNetwork(network: SupportedNetworks): NetworkConfig | null { | ||
if (networks[network]) { | ||
return networks[network]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export function getNetworkByChainId(chainId: number): NetworkConfig | null { | ||
return ( | ||
Object.values(networks).find(network => network.chainId === chainId) || null | ||
); | ||
} | ||
|
||
/** | ||
* Retrieves the network configuration object by name or alias. | ||
* | ||
* @param {string | SupportedNetworks} network - The name or alias of the network. | ||
* @return {NetworkConfig | null} The network configuration object if found, or `null` if not found. | ||
*/ | ||
export function getNetworkByNameOrAlias( | ||
network: string | SupportedNetworks | ||
): NetworkConfig | null { | ||
const networkConfig = | ||
getNetworkByAlias(network) || getNetwork(network as SupportedNetworks); | ||
if (networkConfig) { | ||
return networkConfig; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Retrieves the network configuration object based on the given alias. | ||
* | ||
* @param {string} alias - The alias of the network. | ||
* @return {NetworkConfig | null} The network configuration object corresponding to the alias, or null if not found. | ||
*/ | ||
export function getNetworkByAlias(alias: string): NetworkConfig | null { | ||
const networkName = getNetworkNameByAlias(alias); | ||
if (networkName) { | ||
return getNetwork(networkName); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Retrieves the network name by its alias. If the name is already supported it returns the alias back as name | ||
* | ||
* @param {string} alias - The alias of the network. | ||
* @return {SupportedNetworks | null} The network name corresponding to the alias, or null if no match is found. | ||
*/ | ||
export function getNetworkNameByAlias(alias: string): SupportedNetworks | null { | ||
if (Object.values(SupportedNetworks).includes(alias as SupportedNetworks)) { | ||
return alias as SupportedNetworks; | ||
} | ||
|
||
for (const networkName of Object.values(SupportedNetworks)) { | ||
const network = getNetwork(networkName); | ||
if (network) { | ||
const aliases = Object.values(network.aliases); | ||
if (aliases.includes(alias)) { | ||
return networkName; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
export function getNetworkAlias( | ||
aliasName: SupportedAliases, | ||
network: SupportedNetworks | ||
): string | null { | ||
const networkConfig = getNetwork(network); | ||
if (!networkConfig) { | ||
return null; | ||
} | ||
return networkConfig.aliases[aliasName] || network; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './types'; |
Oops, something went wrong.