Skip to content

Commit

Permalink
feat: Use addresses from mangrove-deployments and context-addresses p…
Browse files Browse the repository at this point in the history
…ackages (#651)
  • Loading branch information
espendk authored Nov 15, 2023
1 parent 8f12d00 commit 2de8027
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 186 deletions.
33 changes: 5 additions & 28 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 All @@ -61,23 +39,23 @@ jobs:
- name: Foundry Setup
uses: mangrovedao/.github/.github/actions/foundry-setup@master

- name: Solidity Compile
- name: Build
run: yarn run build

# Pinned forks are used in tests and utilize secrets. For PRs from forks these are not available
# Let the tests attempt to run with demo endpoints which are more unstable.
- name: Mangrove Solidity Tests (fast)
- name: Solidity Tests (fast)
run: yarn run test:fast
env:
POLYGON_NODE_URL: ${{ secrets.POLYGON_NODE_URL || 'https://polygon.llamarpc.com' }}
MUMBAI_NODE_URL: ${{ secrets.MUMBAI_NODE_URL || 'unused' }}

# Memory intensive tests run without -vvv as GitHub actions otherwise cancels the step due to memory usage
- name: Mangrove Solidity Tests (memory intensive)
- name: Solidity Tests (memory intensive)
run: yarn run test:memory-intensive

# For push runs we also create a coverage report
- name: Create coverage report for mangrove-solidity
- name: Create coverage report
if: github.event_name != 'pull_request'
run: forge coverage --report lcov
env:
Expand All @@ -92,7 +70,7 @@ jobs:
if: github.event_name != 'pull_request'
run: echo "::set-output name=sha_for_head::$(git rev-parse HEAD)"

- name: Upload to Coveralls for mangrove-solidity
- name: Upload to Coveralls
uses: coverallsapp/github-action@master
if: github.event_name != 'pull_request'
with:
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;
94 changes: 94 additions & 0 deletions copyContextAddresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const contextAddresses = require("@mangrovedao/context-addresses");
const fs = require("fs");
const path = require("path");
const config = require("./config");

const script = path.basename(__filename);

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();
process.exit(0);
}

console.log(`${script}: Copying context addresses...`);

// 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,
});
}
}
}
}

// Create the addresses files with the loaded context addresses
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),
);
}

console.log(`${script}: ...Done copying context addresses`);
Loading

0 comments on commit 2de8027

Please sign in to comment.