Skip to content

Commit

Permalink
Chore: Change all RPCs to public RPC (#66)
Browse files Browse the repository at this point in the history
* ci:change to public rpc

* feat: add change to changelog and update the package version

* feat: define new rpc urls

* feat: add needed index

* ci: update changelog

* feat: add initializer function to provide the rpc apiKey to the networks configuration

* ci: remove not needed console logs

* feat: move the init function to the network file, and complete the rpc url with the api key

* ci: change the string char

* feat: remove the rpc url from the networks and add a function to set the value given the rpc and the api key

* feat: update the changelog and the README

* ci: update readme

* ci: remove comment

* feat: make exception with base goerli when setting the url

---------

Co-authored-by: Claudia <[email protected]>
  • Loading branch information
Rekard0 and clauBv23 authored Mar 12, 2024
1 parent 76e99a1 commit bb86a7b
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 16 deletions.
10 changes: 10 additions & 0 deletions configs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ 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.4.0

### Added

- Add `addRpcUrlToNetwork` function to set the network RPC url, the function will receive the API_KEY and the RPCs URL for the SupportedNetworks.

### Removed

- Removed the RPC URL from the networks configuration.

## v0.3.0

### Added
Expand Down
3 changes: 2 additions & 1 deletion configs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ configurations necessary for the development of plugins and the OSx protocol.
This includes:

- Networks
- RPC url
- if it is a testnet or not
- chain ID
- alias for ethers and Alchemy subgraph
Expand All @@ -17,6 +16,8 @@ This includes:
- Block number when the contract was deployed (which can differ from when the
contract was activated and put in use)

The configuration doesn't provide the RPC URL by default, but you can set your preferred ones with the `addRpcUrlToNetwork` function.

## Installation

Use [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/) to install
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.3.0",
"version": "0.4.0",
"license": "AGPL-3.0-or-later",
"typings": "dist/index.d.ts",
"main": "dist/index.js",
Expand Down
2 changes: 2 additions & 0 deletions configs/src/networks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './types';
export * from './getters';
export * from './networks';
44 changes: 32 additions & 12 deletions configs/src/networks/networks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {NetworkConfigs, SupportedNetworks} from './types';
import {NetworkConfigs, SupportedNetworks, NetworkRpcUrl} from './types';

export const networks: NetworkConfigs = {
[SupportedNetworks.MAINNET]: {
url: 'https://rpc.tenderly.co/fork/d3168a50-0941-42e2-8b9b-bf544c60c356',
isTestnet: false,
chainId: 1,
name: SupportedNetworks.MAINNET,
Expand All @@ -11,21 +10,18 @@ export const networks: NetworkConfigs = {
},
},
[SupportedNetworks.GOERLI]: {
url: 'https://goerli.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: true,
chainId: 5,
name: SupportedNetworks.GOERLI,
aliases: {},
},
[SupportedNetworks.SEPOLIA]: {
url: 'https://sepolia.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: true,
chainId: 11155111,
name: SupportedNetworks.SEPOLIA,
aliases: {},
},
[SupportedNetworks.POLYGON]: {
url: 'https://polygon-mainnet.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: false,
chainId: 137,
feesUrl: 'https://gasstation-mainnet.matic.network/v2',
Expand All @@ -37,7 +33,6 @@ export const networks: NetworkConfigs = {
},
},
[SupportedNetworks.MUMBAI]: {
url: 'https://polygon-mumbai.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: true,
chainId: 80001,
feesUrl: 'https://gasstation-mumbai.matic.today/v2',
Expand All @@ -49,7 +44,6 @@ export const networks: NetworkConfigs = {
},
},
[SupportedNetworks.BASE]: {
url: 'https://developer-access-mainnet.base.org',
isTestnet: false,
chainId: 8453,
gasPrice: 1000,
Expand All @@ -59,7 +53,6 @@ export const networks: NetworkConfigs = {
},
},
[SupportedNetworks.BASE_GOERLI]: {
url: 'https://goerli.base.org',
isTestnet: true,
chainId: 84531,
gasPrice: 1000000,
Expand All @@ -69,7 +62,6 @@ export const networks: NetworkConfigs = {
},
},
[SupportedNetworks.BASE_SEPOLIA]: {
url: 'https://sepolia.base.org',
isTestnet: true,
chainId: 84532,
gasPrice: 1000000,
Expand All @@ -79,7 +71,6 @@ export const networks: NetworkConfigs = {
},
},
[SupportedNetworks.ARBITRUM]: {
url: 'https://arbitrum-mainnet.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: false,
chainId: 42161,
name: SupportedNetworks.ARBITRUM,
Expand All @@ -88,7 +79,6 @@ export const networks: NetworkConfigs = {
},
},
[SupportedNetworks.ARBITRUM_SEPOLIA]: {
url: 'https://arbitrum-sepolia.infura.io/v3/481a4cdc7c774286b8627f21c6827f48',
isTestnet: true,
chainId: 421614,
name: SupportedNetworks.ARBITRUM_SEPOLIA,
Expand All @@ -97,10 +87,40 @@ export const networks: NetworkConfigs = {
},
},
[SupportedNetworks.LOCAL]: {
url: 'http://localhost:8545',
isTestnet: true,
chainId: 31337,
name: SupportedNetworks.LOCAL,
aliases: {},
},
};

export const networksAlchemyRpcUrl: NetworkRpcUrl = {
[SupportedNetworks.MAINNET]: 'https://eth-mainnet.g.alchemy.com/v2/',
[SupportedNetworks.GOERLI]: 'https://eth-goerli.g.alchemy.com/v2/',
[SupportedNetworks.SEPOLIA]: 'https://eth-sepolia.g.alchemy.com/v2/',
[SupportedNetworks.POLYGON]: 'https://polygon-mainnet.g.alchemy.com/v2/',
[SupportedNetworks.MUMBAI]: 'https://polygon-mumbai.g.alchemy.com/v2/',
[SupportedNetworks.BASE]: 'https://base-mainnet.g.alchemy.com/v2/',
[SupportedNetworks.BASE_GOERLI]: 'https://goerli.base.org',
[SupportedNetworks.BASE_SEPOLIA]: 'https://base-sepolia.g.alchemy.com/v2/',
[SupportedNetworks.ARBITRUM]: 'https://arb-mainnet.g.alchemy.com/v2/',
[SupportedNetworks.ARBITRUM_SEPOLIA]: 'https://arb-sepolia.g.alchemy.com/v2/',
[SupportedNetworks.LOCAL]: 'http://localhost:8545',
};

export function addRpcUrlToNetwork(
apiKey: string,
networksRpcUrl: NetworkRpcUrl = networksAlchemyRpcUrl
) {
// add the api key to the network urls
for (const network of Object.values(SupportedNetworks)) {
if (
network == SupportedNetworks.LOCAL ||
network == SupportedNetworks.BASE_GOERLI
) {
networks[network].url = networksRpcUrl[network];
} else {
networks[network].url = `${networksRpcUrl[network]}${apiKey}`;
}
}
}
6 changes: 5 additions & 1 deletion configs/src/networks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export enum SupportedNetworks {
}

export type NetworkConfig = {
url: string;
url?: string;
isTestnet: boolean;
chainId: number;
name: SupportedNetworks;
Expand All @@ -35,3 +35,7 @@ export type NetworkAliases = {
export type NetworkConfigs = {
[network in SupportedNetworks]: NetworkConfig;
};

export type NetworkRpcUrl = {
[index in SupportedNetworks]: string;
};
27 changes: 26 additions & 1 deletion configs/src/test/unit/networks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
getNetworkByNameOrAlias,
getNetworkNameByAlias,
} from '../../networks/getters';
import {networks} from '../../networks/networks';
import {
networks,
networksAlchemyRpcUrl,
addRpcUrlToNetwork,
} from '../../networks/networks';

describe('Deployments', () => {
describe('getNetwork', () => {
Expand Down Expand Up @@ -139,4 +143,25 @@ describe('Deployments', () => {
});
});
});
describe('addRpcUrlToNetwork', () => {
it('should add the rpc url to the networks', () => {
const apiKey: string = 'TEST_API_KEY';
addRpcUrlToNetwork(apiKey, networksAlchemyRpcUrl);
Object.values(SupportedNetworks).map(network => {
if (network === SupportedNetworks.LOCAL) {
expect(networks[network].url).toBe(
networksAlchemyRpcUrl[SupportedNetworks.LOCAL]
);
} else if (network === SupportedNetworks.BASE_GOERLI) {
expect(networks[network].url).toBe(
networksAlchemyRpcUrl[SupportedNetworks.BASE_GOERLI]
);
} else {
expect(networks[network].url).toBe(
`${networksAlchemyRpcUrl[network]}${apiKey}`
);
}
});
});
});
});

0 comments on commit bb86a7b

Please sign in to comment.