Skip to content

Commit

Permalink
feat(configs): adds helper function for networks and deployments (#44)
Browse files Browse the repository at this point in the history
* fix(configs): changes to be commonjs package
feat(configs): improves typings for networks
feat(configs): adds helper function for networks and deployments

* chore(configs): applies formatting

* deploy(configs): bumps version to 0.1.0

* fix(configs): typo in SupportedVerions

* fix(configs): typo in NetworkDeploymnets
docs(configs): adds more clarifying comments

* fix(configs): corrects SupportedVersions enum keys

* Add tests
Add missing sepolia contract
Add NetworksAliases enum
Add CHANGELOG
Add ContractNames enum
Add exported `contracts` object
Add `getNetworkAlias` function

* fix comments

* fix prettier

* fix changelog

* add generic tests

* fix lint
+

* update contract names enum

* update type with enum value

* fix networkDeployment type

---------

Co-authored-by: Jose Manuel Mariñas Bascoy <[email protected]>
  • Loading branch information
mathewmeconry and josemarinas authored Jan 24, 2024
1 parent 2de5fd2 commit 1b8ca59
Show file tree
Hide file tree
Showing 14 changed files with 2,795 additions and 134 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,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.1.0

### 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.
6 changes: 6 additions & 0 deletions configs/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/'],
};
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 | 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,
};
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

0 comments on commit 1b8ca59

Please sign in to comment.