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: Add missing methods and local network support #51

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 12 additions & 12 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
contracts:
- changed-files:
- any-glob-to-any-file:
- ./contracts/**/*
- ./contracts/*
- ./.github/workflows/contracts-*.yml
- 'contracts/**/*'
- 'contracts/*'
- '.github/workflows/contracts-*.yml'

sdk:
- changed-files:
- any-glob-to-any-file:
- ./sdk/**/*
- ./sdk/*
- ./.github/workflows/sdk-*.yml
- 'sdk/**/*'
- 'sdk/*'
- '.github/workflows/sdk-*.yml'

subgraph:
- changed-files:
- any-glob-to-any-file:
- ./subgraph/**/*
- ./subgraph/*
- ./.github/workflows/subgraph-*.yml
- 'subgraph/**/*'
- 'subgraph/*'
- '.github/workflows/subgraph-*.yml'

configs:
- changed-files:
- any-glob-to-any-file:
- ./configs/**/*
- ./configs/*
- ./.github/workflows/configs-*.yml
- 'configs/**/*'
- 'configs/*'
- '.github/workflows/configs-*.yml'
11 changes: 11 additions & 0 deletions configs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ 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.2.0

### Added

- `getNetworkByChainId` function
- Support for local networks

### Changed

- All undefined return values to `null` instead of `undefined`

## v0.1.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion 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.1.0",
"version": "0.2.0",
"license": "AGPL-3.0-or-later",
"typings": "dist/index.d.ts",
"main": "dist/index.js",
Expand Down
4 changes: 4 additions & 0 deletions configs/src/deployments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const contracts: {
baseSepolia,
arbitrum,
arbitrumSepolia,
local: {
[SupportedVersions.V1_0_0]: {} as NetworkDeployment,
[SupportedVersions.V1_3_0]: {} as NetworkDeployment,
},
};

/**
Expand Down
43 changes: 33 additions & 10 deletions configs/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export function getNetwork(network: SupportedNetworks): NetworkConfig | null {
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.
*
Expand Down Expand Up @@ -85,89 +91,106 @@ export function getNetworkAlias(
}

export const networks: NetworkConfigs = {
mainnet: {
[SupportedNetworks.MAINNET]: {
url: 'https://rpc.tenderly.co/fork/d3168a50-0941-42e2-8b9b-bf544c60c356',
isTestnet: false,
chainId: 1,
name: SupportedNetworks.MAINNET,
aliases: {
ethers5: 'homestead',
},
},
goerli: {
[SupportedNetworks.GOERLI]: {
url: 'https://goerli.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: true,
chainId: 5,
name: SupportedNetworks.GOERLI,
aliases: {},
},
sepolia: {
[SupportedNetworks.SEPOLIA]: {
url: 'https://sepolia.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: true,
chainId: 11155111,
name: SupportedNetworks.SEPOLIA,
aliases: {},
},
polygon: {
[SupportedNetworks.POLYGON]: {
url: 'https://polygon-mainnet.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: false,
chainId: 137,
feesUrl: 'https://gasstation-mainnet.matic.network/v2',
name: SupportedNetworks.POLYGON,
aliases: {
ethers5: 'matic',
ethers6: 'matic',
alchemySubgraphs: 'matic',
},
},
mumbai: {
[SupportedNetworks.MUMBAI]: {
url: 'https://polygon-mumbai.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: true,
chainId: 80001,
feesUrl: 'https://gasstation-mumbai.matic.today/v2',
name: SupportedNetworks.MUMBAI,
aliases: {
ethers5: 'maticmum',
ethers6: 'matic-mumbai',
alchemySubgraphs: 'mumbai',
},
},
baseMainnet: {
[SupportedNetworks.BASE]: {
url: 'https://developer-access-mainnet.base.org',
isTestnet: false,
chainId: 8453,
gasPrice: 1000,
name: SupportedNetworks.BASE,
aliases: {
alchemySubgraphs: 'base',
},
},
baseGoerli: {
[SupportedNetworks.BASE_GOERLI]: {
url: 'https://goerli.base.org',
isTestnet: true,
chainId: 84531,
gasPrice: 1000000,
name: SupportedNetworks.BASE_GOERLI,
aliases: {
alchemySubgraphs: 'base-testnet',
},
},
baseSepolia: {
[SupportedNetworks.BASE_SEPOLIA]: {
url: 'https://sepolia.base.org',
isTestnet: true,
chainId: 84532,
gasPrice: 1000000,
name: SupportedNetworks.BASE_SEPOLIA,
aliases: {
alchemySubgraphs: 'base-sepolia',
},
},
arbitrum: {
[SupportedNetworks.ARBITRUM]: {
url: 'https://arbitrum-mainnet.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: false,
chainId: 42161,
name: SupportedNetworks.ARBITRUM,
aliases: {
alchemySubgraphs: 'arbitrum-one',
},
},
arbitrumSepolia: {
[SupportedNetworks.ARBITRUM_SEPOLIA]: {
url: 'https://arbitrum-sepolia.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: true,
chainId: 421614,
name: SupportedNetworks.ARBITRUM_SEPOLIA,
aliases: {
alchemySubgraphs: 'arbitrum-sepolia',
},
},
[SupportedNetworks.LOCAL]: {
url: 'http://localhost:8545',
isTestnet: true,
chainId: 31337,
name: SupportedNetworks.LOCAL,
aliases: {},
},
};
48 changes: 30 additions & 18 deletions configs/src/test/unit/networks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
getNetwork,
getNetworkAlias,
getNetworkByAlias,
getNetworkByChainId,
getNetworkByNameOrAlias,
getNetworkNameByAlias,
networks,
Expand Down Expand Up @@ -36,8 +37,19 @@ describe('Deployments', () => {
});
});
describe('getNetworkByNameOrAlias', () => {
it('should return the correct value', () => {
let inputs = Object.values(SupportedNetworks)
it('should return a network given a name', () => {
const inputs = Object.values(SupportedNetworks).map(network => {
return {
network,
expected: networks[network],
};
});
inputs.map(({network, expected}) => {
expect(getNetworkByNameOrAlias(network)).toMatchObject(expected);
});
});
it('should return a network given an alias', () => {
const inputs = Object.values(SupportedNetworks)
.flatMap(nw => {
return Object.values(SupportedAliases).map(alias => {
return {
Expand All @@ -47,23 +59,10 @@ describe('Deployments', () => {
});
})
.filter(({network}) => network !== undefined);

inputs = inputs.concat(
Object.values(SupportedNetworks).map(network => {
return {
network,
expected: networks[network],
};
})
);

inputs.map(({network, expected}) => {
if (!expected) {
expect(getNetworkByNameOrAlias(network as string)).toBeNull();
return;
}
const res = getNetworkByNameOrAlias(network as string);
expect(res).toMatchObject(expected);
expect(getNetworkByNameOrAlias(network as string)).toMatchObject(
expected
);
});
});
});
Expand Down Expand Up @@ -123,4 +122,17 @@ describe('Deployments', () => {
});
});
});
describe('getNetworkByChainId', () => {
it('should get the network given the chainId', () => {
const inputs = Object.values(SupportedNetworks).map(network => {
return {
network: networks[network].chainId,
expected: networks[network],
};
});
inputs.map(({network, expected}) => {
expect(getNetworkByChainId(network)).toBe(expected);
});
});
});
});
2 changes: 2 additions & 0 deletions configs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type NetworkConfig = {
url: string;
isTestnet: boolean;
chainId: number;
name: SupportedNetworks;
feesUrl?: string;
gasPrice?: number;
aliases: NetworkAliases;
Expand Down Expand Up @@ -32,6 +33,7 @@ export enum SupportedNetworks {
BASE_SEPOLIA = 'baseSepolia',
ARBITRUM = 'arbitrum',
ARBITRUM_SEPOLIA = 'arbitrumSepolia',
LOCAL = 'local',
}

// the entries in this enum has to be in order from
Expand Down
Loading