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

Check deployment outputs #1284

Merged
merged 18 commits into from
May 17, 2022
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
51 changes: 40 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- master
pull_request:
branches: "*"
branches: '*'

jobs:
lint:
Expand All @@ -20,7 +20,7 @@ jobs:
uses: actions/cache@v2
id: cache
with:
path: "**/node_modules"
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
Expand All @@ -40,7 +40,7 @@ jobs:
uses: actions/cache@v2
id: cache
with:
path: "**/node_modules"
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
Expand All @@ -60,7 +60,7 @@ jobs:
uses: actions/cache@v2
id: cache
with:
path: "**/node_modules"
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
Expand All @@ -82,7 +82,7 @@ jobs:
uses: actions/cache@v2
id: cache
with:
path: "**/node_modules"
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
Expand All @@ -104,7 +104,7 @@ jobs:
uses: actions/cache@v2
id: cache
with:
path: "**/node_modules"
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
Expand All @@ -126,7 +126,7 @@ jobs:
uses: actions/cache@v2
id: cache
with:
path: "**/node_modules"
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
Expand All @@ -148,7 +148,7 @@ jobs:
uses: actions/cache@v2
id: cache
with:
path: "**/node_modules"
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
Expand All @@ -170,7 +170,7 @@ jobs:
uses: actions/cache@v2
id: cache
with:
path: "**/node_modules"
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
Expand All @@ -192,7 +192,7 @@ jobs:
uses: actions/cache@v2
id: cache
with:
path: "**/node_modules"
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
Expand All @@ -214,7 +214,7 @@ jobs:
uses: actions/cache@v2
id: cache
with:
path: "**/node_modules"
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
Expand All @@ -224,6 +224,35 @@ jobs:
- name: Test
run: yarn workspace @balancer-labs/v2-governance-scripts test

check-deployments:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install node
uses: actions/setup-node@v1
with:
node-version: 14
- name: Cache
uses: actions/cache@v2
id: cache
with:
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
if: steps.cache.outputs.cache-hit != 'true'
- name: Compile balancer-js
run: yarn workspace @balancer-labs/balancer-js build
- name: Prepare Config
run: yarn workspace @balancer-labs/v2-deployments ci:prepare-config
env:
ALCHEMY_MAINNET_ARCHIVE_ENDPOINT: ${{ secrets.ALCHEMY_MAINNET_ARCHIVE_ENDPOINT }}
INFURA_POLYGON_NONARCHIVE_ENDPOINT: ${{ secrets.INFURA_POLYGON_NONARCHIVE_ENDPOINT }}
INFURA_ARBITRUM_NONARCHIVE_ENDPOINT: ${{ secrets.INFURA_ARBITRUM_NONARCHIVE_ENDPOINT }}
INFURA_OPTIMISM_NONARCHIVE_ENDPOINT: ${{ secrets.INFURA_OPTIMISM_NONARCHIVE_ENDPOINT }}
- name: Check Deployments
run: yarn workspace @balancer-labs/v2-deployments check

benchmark:
runs-on: ubuntu-latest
steps:
Expand Down
31 changes: 31 additions & 0 deletions pkg/deployments/ci/prepare-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import path from 'path';
import { homedir } from 'os';
import { mkdirSync, writeFileSync } from 'fs';

const HH_CONFIG_FILENAME = `${homedir()}/.hardhat/networks.json`;

if (process.env.CI) {
const content = `{
"networks": {
"mainnet": {
"url": "${process.env.ALCHEMY_MAINNET_ARCHIVE_ENDPOINT}"
},
"polygon": {
"url": "${process.env.INFURA_POLYGON_NONARCHIVE_ENDPOINT}"
},
"arbitrum": {
"url": "${process.env.INFURA_ARBITRUM_NONARCHIVE_ENDPOINT}"
},
"optimism": {
"url": "${process.env.INFURA_OPTIMISM_NONARCHIVE_ENDPOINT}"
}
},
"defaultConfig": {
"gasPrice": "auto",
"gasMultiplier": 1
}
}`;

mkdirSync(path.dirname(HH_CONFIG_FILENAME), { recursive: true });
writeFileSync(HH_CONFIG_FILENAME, content);
}
30 changes: 29 additions & 1 deletion pkg/deployments/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import test from './src/test';
import Task, { TaskMode } from './src/task';
import Verifier from './src/verifier';
import { Logger } from './src/logger';
import path from 'path';
import { existsSync, readdirSync, statSync } from 'fs';

task('deploy', 'Run deployment task')
.addParam('id', 'Deployment task ID')
Expand All @@ -28,7 +30,7 @@ task('deploy', 'Run deployment task')
}
);

task('verify-contract', 'Run verification for a given contract')
task('verify-contract', `Verify a task's deployment on a block explorer`)
.addParam('id', 'Deployment task ID')
.addParam('name', 'Contract name')
.addParam('address', 'Contract address')
Expand All @@ -50,6 +52,32 @@ task('verify-contract', 'Run verification for a given contract')
}
);

task('check-deployments', `Check that all tasks' deployments correspond to their build-info and inputs`)
.addOptionalParam('id', 'Specific task ID')
.setAction(async (args: { id?: string; force?: boolean; verbose?: boolean }, hre: HardhatRuntimeEnvironment) => {
// The force argument above is actually not passed (and not required or used in CHECK mode), but it is the easiest
// way to address type issues.

Logger.setDefaults(false, args.verbose || false);

if (args.id) {
await new Task(args.id, TaskMode.CHECK, hre.network.name).run(args);
} else {
const taskDirectory = path.resolve(__dirname, './tasks');

for (const taskID of readdirSync(taskDirectory)) {
const outputDir = path.resolve(taskDirectory, taskID, 'output');
if (existsSync(outputDir) && statSync(outputDir).isDirectory()) {
const outputFiles = readdirSync(outputDir);
if (outputFiles.some((outputFile) => outputFile.includes(hre.network.name))) {
// Not all tasks have outputs for all networks, so we skip those that don't
await new Task(taskID, TaskMode.CHECK, hre.network.name).run(args);
}
}
}
}
});

task(TASK_TEST)
.addOptionalParam('fork', 'Optional network name to be forked block number to fork in case of running fork tests.')
.addOptionalParam('blockNumber', 'Optional block number to fork in case of running fork tests.', undefined, types.int)
Expand Down
4 changes: 3 additions & 1 deletion pkg/deployments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
],
"scripts": {
"build": "tsc",
"check": "hardhat check-deployments --network mainnet && hardhat check-deployments --network polygon && hardhat check-deployments --network arbitrum && hardhat check-deployments --network optimism",
"lint": "eslint . --ext .ts --ignore-path ../../.eslintignore --max-warnings 0",
"prepack": "yarn build",
"test": "hardhat test ./**/test/*.ts --fork mainnet --block-number 14769900"
"test": "hardhat test ./**/test/*.ts --fork mainnet --block-number 14769900",
"ci:prepare-config": "ts-node ci/prepare-config.ts"
},
"devDependencies": {
"@balancer-labs/balancer-js": "workspace:*",
Expand Down
15 changes: 14 additions & 1 deletion pkg/deployments/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ export async function instanceAt(artifact: Artifact, address: string): Promise<C
return ethers.getContractAt(artifact.abi, address);
}

export function deploymentTxData(artifact: Artifact, args: Array<Param> = [], libs?: Libraries): string {
if (libs) artifact = linkBytecode(artifact, libs);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const encodedConstructorArguments = new utils.Interface(artifact.abi as any[]).encodeDeploy(args);

// Solidity contracts are deployed by sending a transaction with their creation code, concatenated by the abi-encoded
// constructor arguments.
// We remove the first two characters of the encoded constructor arguments as ethers returns a string with the "0x"
// prefix.
return `0x${artifact.evm.bytecode.object}${encodedConstructorArguments.substring(2)}`;
}

function linkBytecode(artifact: Artifact, libraries: Libraries): Artifact {
let bytecode = artifact.evm.bytecode.object;
for (const [, fileReferences] of Object.entries(artifact.evm.bytecode.linkReferences)) {
Expand All @@ -38,6 +51,6 @@ function linkBytecode(artifact: Artifact, libraries: Libraries): Artifact {
}
}

artifact.evm.bytecode.object = bytecode;
artifact.evm.bytecode.object = bytecode.toLowerCase();
return artifact;
}
Loading