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(configs): adds helper function for networks and deployments #44

Merged
merged 15 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ ignorePatterns:
- '.DS_Store'
- .pnp.*
- 'node_modules'
- '*.config.js'
45 changes: 45 additions & 0 deletions configs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Aragon OSx Commons Configs

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v0.0.3

### Added

- Types for Deployments
- `SupportedNetworks` enum
- `SupportedAliases` enum
- `SupportedVersions` enum
- Typed deployments
- `contracts` object with all contracts
- `getNetworkAlias` function
- `getNetworkNameFromAlias` function
- `getNetworkDeployments` function
- `getNetworkDeploymentForVersion` function
- `getLatestNetworkDeployment` function
- `getNetwork` function
- `getNetworkByNameOrAlias` function
- `getNetworkByAlias` function
- `getNetworkNameByAlias` function
- `getNetworkAlias` function

## v0.0.2

### Added

- Deployment JSON files for:
- Mainnet
- Goerli
- Sepolia
- Polygon
- Mumbai
- Base Mainnet
- Base Goerli
- Base Sepolia
- Arbitrum
- Arbitrum Sepolia
- JSON file with the supported networks and the default rpcs, chainIds, and aliases on other services.
- Typing for the Network Configs.
5 changes: 5 additions & 0 deletions configs/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
8 changes: 6 additions & 2 deletions configs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aragon/osx-commons-configs",
"author": "Aragon Association",
"version": "0.0.2",
"version": "0.1.0",
"license": "AGPL-3.0-or-later",
"typings": "dist/index.d.ts",
"main": "dist/index.js",
Expand All @@ -19,7 +19,8 @@
"lint:ts": "cd .. && yarn run lint:configs:ts",
"prepare": "yarn run build",
"analyze": "size-limit --why",
"clean": "rm -Rf dist"
"clean": "rm -Rf dist",
"test": "jest"
},
"peerDependencies": {},
"husky": {
Expand All @@ -28,6 +29,9 @@
}
},
"devDependencies": {
"@types/jest": "^29.5.11",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
}
}
92 changes: 92 additions & 0 deletions configs/src/deployments/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
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,
};

/**
* 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 | undefined} The network deployment for the specified version, or undefined if not found.
*/
export function getNetworkDeploymentForVersion(
network: SupportedNetworks,
version: SupportedVersions
): NetworkDeployment | undefined {
return getNetworkDeployments(network)[version];
}

/**
* Retrieves the latest network deployment for the specified network.
*
* @param {SupportedNetworks} network - The network to retrieve the deployment for.
* @return {NetworkDeployment | undefined} The latest network deployment, or undefined if not found.
*/
export function getLatestNetworkDeployment(
network: SupportedNetworks
): NetworkDeployment | undefined {
const versions = Object.values(SupportedVersions).reverse();
for (const version of versions) {
const deployment = getNetworkDeploymentForVersion(network, version);
if (deployment) {
return deployment;
}
}
return undefined;
}

export {
contracts,
mainnet,
goerli,
sepolia,
polygon,
mumbai,
baseMainnet,
baseGoerli,
baseSepolia,
arbitrum,
arbitrumSepolia,
};
5 changes: 5 additions & 0 deletions configs/src/deployments/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@
"address": "0x917c2ab96c40adefd08d240409485d8b606423e3",
"blockNumber": 4421515,
"deploymentTx": "0x94e2d1ff08572017d4761ad5837564b6c6577b738098aed22f50b5199fffe147"
},
"DAOBase": {
"address": "0x2C9c5e8F559DBBEc962f7CCd295DBc4183cd2168",
"blockNumber": 4421517,
"deploymentTx": "0xcbfcb1b5d907ebda07123addf97f5440981347a5e70b219bcb38f667608c5901"
}
}
}
31 changes: 2 additions & 29 deletions configs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
import * as arbitrum from './deployments/arbitrum.json';
import * as arbitrumSepolia from './deployments/arbitrumSepolia.json';
import * as baseGoerli from './deployments/baseGoerli.json';
import * as baseMainnet from './deployments/baseMainnet.json';
import * as baseSepolia from './deployments/baseSepolia.json';
import * as goerli from './deployments/goerli.json';
import * as mainnet from './deployments/mainnet.json';
import * as mumbai from './deployments/mumbai.json';
import * as polygon from './deployments/polygon.json';
import * as sepolia from './deployments/sepolia.json';
import * as networks from './networks.json';
import {NetworkConfigs} from './types';

export * from './networks';
export * from './types';

const networksTyped: NetworkConfigs = networks;

export {
networksTyped as networks,
arbitrum,
arbitrumSepolia,
baseGoerli,
baseMainnet,
baseSepolia,
goerli,
mainnet,
mumbai,
polygon,
sepolia,
};
export * from './deployments/index';
98 changes: 0 additions & 98 deletions configs/src/networks.json

This file was deleted.

Loading