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: Use addresses from mangrove-deployments and context-addresses packages #651

Merged
merged 13 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
23 changes: 0 additions & 23 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,6 @@ concurrency:
env:
NODE_ENV: test
jobs:
file-guard:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
addresses:
- 'addresses/deployed/*.json'

- name: Fail if addresses changed unless PR has 'update address' label
if: >
( github.event_name == 'pull_request'
&& !contains(github.event.pull_request.labels.*.name,'update address')
&& steps.changes.outputs.addresses == 'true')
uses: actions/github-script@v7
with:
script: core.setFailed('You have changed an address in mangrove-core (deployed/*.json). PR must be marked \'update address\' for CI to run')

# ==== Job: Build and test mangrove-core
mangrove-core:
runs-on: ubuntu-22.0-4core
Expand Down Expand Up @@ -125,7 +103,6 @@ jobs:
if: always()

needs:
- file-guard
- mangrove-core

runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions addresses/context/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore files
*
# Ignore subdirectories
*/
# Don't ignore the README nor this file
!.gitignore
!README.md
7 changes: 7 additions & 0 deletions addresses/context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# context directory

The committed version of this directory should be empty (except for this README.md file).

It will contain context addresses read by forge script. None of them will be committed.

This directory must exist so forge script can write to it.
26 changes: 0 additions & 26 deletions addresses/context/arbitrum.json

This file was deleted.

14 changes: 0 additions & 14 deletions addresses/context/goerli.json

This file was deleted.

26 changes: 0 additions & 26 deletions addresses/context/matic.json

This file was deleted.

22 changes: 0 additions & 22 deletions addresses/context/maticmum.json

This file was deleted.

7 changes: 7 additions & 0 deletions addresses/deployed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore files
*
# Ignore subdirectories
*/
# Don't ignore the README nor this file
!.gitignore
!README.md
7 changes: 7 additions & 0 deletions addresses/deployed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# deployed directory

The committed version of this directory should be empty (except for this README.md file).

It will contain deployment addresses read by forge script. None of them will be committed.

This directory must exist so forge script can write to it.
14 changes: 0 additions & 14 deletions addresses/deployed/arbitrum.json

This file was deleted.

22 changes: 0 additions & 22 deletions addresses/deployed/matic.json

This file was deleted.

30 changes: 0 additions & 30 deletions addresses/deployed/maticmum.json

This file was deleted.

30 changes: 30 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,33 @@ exports.abi_exports = [

// Contracts that should export their ABI + bytecode
exports.full_exports = ["SimpleTestMaker"];

/////////////////////////////////////
// mangrove-deployments configuration

// Whether to fetch deployments from mangrove-deployments.
// Setting this to false allows manually specifying the addresses to use
// by writing them to the JSON files in the addresses/deployed directory.
// This may be useful if one wants to use a non-primary deployment.
// Default is true.
exports.copyDeployments = true;

// The SemVer range describing the versions of the Mangrove core contracts
// to query mangrove-deployments for.
// Default is the latest patch of the current package version.
const packageVersion = require("./package.json").version;
exports.coreDeploymentVersionRangePattern = `^${packageVersion}`;

// Whether to query mangrove-deployments for released (true), unreleased (false),
// or the latest of either (undefined) versions of the core contracts.
// Default is the latest regardless of their release status.
exports.coreDeploymentVersionReleasedFilter = undefined;

//////////////////////////////////
// context-addresses configuration

// Whether to fetch deployments from context-addresses.
// Setting this to false allows manually specifying the addresses to use
// by writing them to the JSON files in the addresses/context directory.
// Default is true.
exports.copyContextAddresses = true;
87 changes: 87 additions & 0 deletions copyContextAddresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const contextAddresses = require("@mangrovedao/context-addresses");
const fs = require("fs");
const path = require("path");
const config = require("./config");

if (!config.copyContextAddresses) {
console.group(
"Skipping copying context addresses from the context-addresses package.",
);
console.log(
"Set copyContextAddresses = true in config.js to enable copying.",
);
console.log("Using addresses/context/*.json files as-is instead.");
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",
};

// Construct the addresses object for each network
const contextAddressesByNetwork = {}; // network name => { name: string, address: string }[]
function getOrCreateNetworkAddresses(networkId) {
const networkName = networkNames[+networkId];
let networkAddresses = contextAddressesByNetwork[networkName];
if (networkAddresses === undefined) {
networkAddresses = [];
contextAddressesByNetwork[networkName] = networkAddresses;
}
return networkAddresses;
}

// Accounts
const allAccounts = contextAddresses.getAllAccounts();
for (const [accountId, account] of Object.entries(allAccounts)) {
for (const [networkId, address] of Object.entries(account.networkAddresses)) {
const networkAddresses = getOrCreateNetworkAddresses(networkId);
networkAddresses.push({
name: accountId,
address: address,
});
}
}

// Token addresses
const allErc20s = contextAddresses.getAllErc20s();
for (const [erc20Id, erc20] of Object.entries(allErc20s)) {
for (const [networkId, networkInstances] of Object.entries(
erc20.networkInstances,
)) {
const networkAddresses = getOrCreateNetworkAddresses(networkId);
for (const [instanceId, networkInstance] of Object.entries(
networkInstances,
)) {
networkAddresses.push({
name: instanceId,
address: networkInstance.address,
});
// Also register the default instance as the token symbol for convenience
if (networkInstance.default) {
networkAddresses.push({
name: erc20.symbol,
address: networkInstance.address,
});
}
}
}
}

// Replace the addresses files with the loaded context addresses
espendk marked this conversation as resolved.
Show resolved Hide resolved
for (const networkName in contextAddressesByNetwork) {
let addressesToWrite = contextAddressesByNetwork[networkName];
const networkAddressesFilePath = path.join(
__dirname,
`./addresses/context/${networkName}.json`,
);
fs.writeFileSync(
networkAddressesFilePath,
JSON.stringify(addressesToWrite, null, 2),
);
}
Loading