Skip to content

Commit

Permalink
feat!: Remove ethers.js network names
Browse files Browse the repository at this point in the history
For interoperability, relying on the non-canonical ethers.js network names is unfortunate. This package doesn't even use ethers.js.
Instead, we now use the canonical chain ID.
  • Loading branch information
espendk committed Nov 8, 2023
1 parent 53958cd commit 2af89e4
Show file tree
Hide file tree
Showing 14 changed files with 9 additions and 31 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 6 additions & 17 deletions copyDeploymentAddresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ if (!config.copyDeployments) {
console.groupEnd();
}

// This is a hack to get the network names because the addresses
// file names use non-canonical network names from ethers.js
const networkNames = {
1: "mainnet",
5: "goerli",
137: "matic",
42161: "arbitrum",
80001: "maticmum",
};

// Query deployments based on the configuration in config.js
const mangroveVersionDeployments = deployments.getMangroveVersionDeployments({
version: config.coreDeploymentVersionRangePattern,
Expand All @@ -48,17 +38,16 @@ const contractsDeployments = [
mgvReaderVersionDeployments,
...allTestErc20VersionDeployments,
].filter((x) => x !== undefined);
const deployedAddresses = {}; // network name => { name: string, address: string }[]
const deployedAddresses = {}; // network ID => { name: string, address: string }[]
// Iterate over each contract deployment and add the addresses to the deployedAddresses object
for (const contractDeployments of contractsDeployments) {
for (const [networkId, networkDeployments] of Object.entries(
contractDeployments.networkAddresses,
)) {
const networkName = networkNames[+networkId];
let networkAddresses = deployedAddresses[networkName];
let networkAddresses = deployedAddresses[networkId];
if (networkAddresses === undefined) {
networkAddresses = [];
deployedAddresses[networkName] = networkAddresses;
deployedAddresses[networkId] = networkAddresses;
}
networkAddresses.push({
name:
Expand All @@ -69,11 +58,11 @@ for (const contractDeployments of contractsDeployments) {
}

// Replace the addresses files with the loaded deployment addresses
for (const networkName in deployedAddresses) {
let addressesToWrite = deployedAddresses[networkName];
for (const networkId in deployedAddresses) {
let addressesToWrite = deployedAddresses[networkId];
const networkAddressesFilePath = path.join(
__dirname,
`./addresses/deployed/${networkName}.json`,
`./addresses/deployed/${networkId}.json`,
);
fs.writeFileSync(
networkAddressesFilePath,
Expand Down
1 change: 0 additions & 1 deletion test/lib/forks/Arbitrum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ contract ArbitrumFork is GenericFork {
constructor() {
CHAIN_ID = 42161;
NAME = "arbitrum"; // must be id used in foundry.toml for rpc_endpoint & etherscan
NETWORK = "arbitrum"; // must be network name inferred by ethers.js
}
}

Expand Down
1 change: 0 additions & 1 deletion test/lib/forks/Ethereum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ contract EthereumFork is GenericFork {
constructor() {
CHAIN_ID = 1;
NAME = "ethereum";
NETWORK = "mainnet";
}
}

Expand Down
9 changes: 3 additions & 6 deletions test/lib/forks/Generic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ Note: when you add a *Fork contract, to have it available in deployment scripts,
remember to add it to the initialized forks in Deployer.sol.*/
contract GenericFork is Script {
uint public INTERNAL_FORK_ID;
uint public CHAIN_ID;
uint public CHAIN_ID; // used as <CHAIN_ID>.json filename
string public NAME = "genericName";
string public NETWORK = "genericNetwork"; // common network name, used as <NETWORK>.json filename
uint public BLOCK_NUMBER;

// context addresses (aave, gas update bot, etc)
Expand Down Expand Up @@ -84,7 +83,7 @@ contract GenericFork is Script {
view
returns (string memory)
{
return string.concat(vm.projectRoot(), "/", pathFromRoot, category, "/", NETWORK, suffix, ".json");
return string.concat(vm.projectRoot(), "/", pathFromRoot, category, "/", vm.toString(CHAIN_ID), suffix, ".json");
}

function readMgvConfig() public view returns (MgvConfig memory) {
Expand Down Expand Up @@ -114,9 +113,7 @@ contract GenericFork is Script {
}

Record[] memory mgvConfigRecords = new Record[](0);
if (readMgvConfigPaths) {
mgvConfigRecords = readMgvConfigAddresses(category);
}
mgvConfigRecords = readMgvConfigAddresses(category);

Record[] memory allRecords = new Record[](envRecords.length + mgvConfigRecords.length);
for (uint i = 0; i < envRecords.length; i++) {
Expand Down
1 change: 0 additions & 1 deletion test/lib/forks/Goerli.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ contract GoerliFork is GenericFork {
constructor() {
CHAIN_ID = 5;
NAME = "goerli";
NETWORK = "goerli";
}
}
1 change: 0 additions & 1 deletion test/lib/forks/Local.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ contract LocalFork is GenericFork {
constructor() {
CHAIN_ID = 31337;
NAME = "local";
NETWORK = "local";
}
}
1 change: 0 additions & 1 deletion test/lib/forks/Mumbai.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ contract MumbaiFork is GenericFork {
constructor() {
CHAIN_ID = 80001;
NAME = "mumbai";
NETWORK = "maticmum";
}
}
1 change: 0 additions & 1 deletion test/lib/forks/Polygon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ contract PolygonFork is GenericFork {
constructor() {
CHAIN_ID = 137;
NAME = "polygon"; // must be id used in foundry.toml for rpc_endpoint & etherscan
NETWORK = "matic"; // must be network name inferred by ethers.js
}
}

Expand Down
1 change: 0 additions & 1 deletion test/lib/forks/TestnetZkevm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ contract TestnetZkevmFork is GenericFork {
constructor() {
CHAIN_ID = 1442;
NAME = "testnet_zkevm";
NETWORK = "testnet_zkevm";
}
}
1 change: 0 additions & 1 deletion test/lib/forks/Zkevm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ contract ZkevmFork is GenericFork {
constructor() {
CHAIN_ID = 1101;
NAME = "zkevm";
NETWORK = "zkevm";
}
}

0 comments on commit 2af89e4

Please sign in to comment.