Skip to content

Commit

Permalink
Make local environment and murmuration use same template-based approach
Browse files Browse the repository at this point in the history
for generating Merkle root used in deploying MerkleDistributor.
  • Loading branch information
ihinsdale committed Nov 16, 2021
1 parent cafd970 commit 63baf9b
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ jobs:
${{ runner.os }}-
- run: npx lerna bootstrap --ci
- run: npm run build
- run: npx lerna run ci_test --stream --scope @goldfinch-eng/client
- run: npx lerna run test --stream --scope @goldfinch-eng/client

functions:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ autotasks/relayer/dist
**/*/deployments/localhost
**/*/deployments/hardhat
**/*/deployments/all_dev.json
**/*/deployments/all_client_test.json

# Misc
.DS_Store
Expand All @@ -107,4 +108,4 @@ goldfinch-frontends-prod-firebase*.json
packages/subgraph/build/
packages/subgraph/data/
packages/subgraph/generated/
packages/subgraph/docker-compose.yml
packages/subgraph/docker-compose.yml
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start:local": "npm run kill-ports && REACT_APP_HARDHAT_FORK= HARDHAT_FORK= npx lerna run start --parallel",
"start:local:liquidity-mining": "npx lerna run generate-merkle-root:local && MERKLE_DISTRIBUTOR_INFO_PATH=./blockchain_scripts/merkle/merkleDistributor/merkleDistributorInfo.dev.json REACT_APP_TOGGLE_REWARDS=true npm run start:local",
"start:murmuration": "npm run kill-ports && npx lerna run start:murmuration --parallel",
"start:murmuration:liquidity-mining": "npm run kill-ports && npx lerna run generate-merkle-root:murmuration && MERKLE_DISTRIBUTOR_INFO_PATH=./blockchain_scripts/merkle/merkleDistributor/merkleDistributorInfo.murmuration.json npx lerna run start:murmuration:liquidity-mining --parallel",
"start:murmuration:liquidity-mining": "npm run kill-ports && npx lerna run generate-merkle-root:murmuration && MERKLE_DISTRIBUTOR_INFO_PATH=./blockchain_scripts/merkle/merkleDistributor/merkleDistributorInfo.dev.json npx lerna run start:murmuration:liquidity-mining --parallel",
"kill-ports": "for i in 4000 4001 3000 5001 8545 8080; do lsof -t -i:$i | xargs -r kill; done",
"test": "npx lerna run test --stream",
"test:client": "npm run test -- --scope @goldfinch-eng/client",
Expand Down
4 changes: 1 addition & 3 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@
"start:murmuration": "PORT=80 REACT_APP_DISABLE_GASLESS=true REACT_APP_HARDHAT_FORK=mainnet HARDHAT_FORK=mainnet MURMURATION=yes npm run start",
"start:murmuration:liquidity-mining": "PORT=80 REACT_APP_DISABLE_GASLESS=true REACT_APP_HARDHAT_FORK= HARDHAT_FORK= MURMURATION=yes npm run start",
"build": "react-app-rewired build",
"check-dev-deployments": "sh -c \"[ -e \"../../packages/protocol/deployments/all_dev.json\" ] && [ \"{}\" != \"$(head -n 1 ../../packages/protocol/deployments/all_dev.json)\" ]\"",
"test": "npm run check-dev-deployments && react-app-rewired test --env=jsdom",
"ci_test": "cd ../protocol && npm run deploy-for-client-test && cd ../client && npm run test",
"test": "cd ../protocol && npm run deploy-for-client-test && cd ../client && react-app-rewired test --env=jsdom",
"eject": "react-scripts eject",
"lint": "npx eslint .",
"lint:fix": "eslint . --fix && prettier . --write",
Expand Down
11 changes: 9 additions & 2 deletions packages/client/src/__tests__/rewards/__utils__/constants.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import deployments from "@goldfinch-eng/protocol/deployments/all_dev.json"
import deployments from "@goldfinch-eng/protocol/deployments/all_client_test.json"

export const blockchain = "ethereum"
export const recipient = "0x0000000000000000000000000000000000000001"
export const network = {name: "localhost", supported: true}
export const blockInfo = {number: 94, timestamp: 1640783491}

const getAbi = (contractName: string) => deployments["31337"].localhost.contracts[contractName].abi
const getAbi = (contractName: string) => {
const contract = deployments["31337"].hardhat.contracts[contractName]
if (contract) {
return contract.abi
} else {
throw new Error(`Failed to identify deployment info for contract: ${contractName}`)
}
}

export const stakingRewardsABI = getAbi("StakingRewards")

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/__tests__/rewards/__utils__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {mock} from "depay-web3-mock"
import {
MerkleDistributorGrantInfo,
MerkleDistributorInfo,
} from "@goldfinch-eng/protocol/blockchain_scripts/merkleDistributor/types"
} from "@goldfinch-eng/protocol/blockchain_scripts/merkle/merkleDistributor/types"
import {CommunityRewards, MerkleDistributor, MerkleDistributorLoaded} from "../../../ethereum/communityRewards"
import {GFI} from "../../../ethereum/gfi"
import {User, UserMerkleDistributor} from "../../../ethereum/user"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "@testing-library/jest-dom"
import {MerkleDistributorGrantInfo} from "@goldfinch-eng/protocol/blockchain_scripts/merkleDistributor/types"
import {MerkleDistributorGrantInfo} from "@goldfinch-eng/protocol/blockchain_scripts/merkle/merkleDistributor/types"
import {MerkleDistributor, CommunityRewards} from "../../../ethereum/communityRewards"
import {GFI} from "../../../ethereum/gfi"
import {User} from "../../../ethereum/user"
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.dev.json
*.murmuration.json
*.client_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ import {findEnvLocal} from "@goldfinch-eng/utils/src/env"
import {program} from "commander"
import dotenv from "dotenv"
import fs from "fs"
import {isArrayOfJsonAccountedGrant, JsonAccountedGrant} from "../types"
import {isArrayOfJsonAccountedGrant, JsonAccountedGrant} from "./types"
dotenv.config({path: findEnvLocal()})

/**
* Script for generating a JSON file containing an array of JsonAccountedGrant objects;
* the file can be used as the input to the `generateMerkleRoot` script.
* Script for generating a JSON blob containing an array of JsonAccountedGrant objects;
* the blob can be saved to a file and used as the input to the `generateMerkleRoot` script.
*
* This script expects as input an array of "template" JsonAccountedGrant objects, whose account
* will be replaced using the addresses read from the MERKLE_DISTRIBUTOR_GRANT_RECIPIENTS
* environment variable.
* environment variable, falling back to the address read from the TEST_USER environment variable.
*/

export function generateMerkleDistributorGrants(templateJson: unknown): JsonAccountedGrant[] {
export function generateGrantsDevFromTemplate(templateJson: unknown): JsonAccountedGrant[] {
if (!isArrayOfJsonAccountedGrant(templateJson)) {
throw new Error("Invalid JSON.")
}
if (!templateJson.length) {
throw new Error("Grants array must not be empty.")
}

const accounts = (process.env.MERKLE_DISTRIBUTOR_GRANT_RECIPIENTS || "").split(",").filter((val) => !!val)
const accounts = (process.env.MERKLE_DISTRIBUTOR_GRANT_RECIPIENTS || process.env.TEST_USER || "")
.split(",")
.filter((val) => !!val)
if (!accounts.length) {
throw new Error("Accounts array must not be empty.")
}
Expand Down Expand Up @@ -52,5 +54,5 @@ if (require.main === module) {
const options = program.opts()
const json = JSON.parse(fs.readFileSync(options.input, {encoding: "utf8"}))

console.log(JSON.stringify(generateMerkleDistributorGrants(json), null, 2))
console.log(JSON.stringify(generateGrantsDevFromTemplate(json), null, 2))
}
10 changes: 6 additions & 4 deletions packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
"test:tenderly": "HARDHAT_FORK=mainnet NODE_ENV=test npx hardhat test $(find test/mainnet_forking/ -name '*.test.ts') --show-stack-traces --network localhost",
"build": "npx hardhat compile && npm run typechain",
"pre-commit": "npx lint-staged",
"generate-merkle-root:local": "node --require hardhat/register ./blockchain_scripts/merkle/merkleDistributor/generateMerkleRoot -i ./blockchain_scripts/merkle/merkleDistributor/grants.dev.json > ./blockchain_scripts/merkle/merkleDistributor/merkleDistributorInfo.dev.json",
"generate-merkle-distributor-grants:murmuration": "node --require hardhat/register ./blockchain_scripts/merkle/merkleDistributor/murmuration/generateMerkleDistributorGrants -i ../../murmuration/grants.template.murmuration.json > ./blockchain_scripts/merkle/merkleDistributor/grants.murmuration.json",
"generate-merkle-root:murmuration": "npm run generate-merkle-distributor-grants:murmuration && node --require hardhat/register ./blockchain_scripts/merkle/merkleDistributor/generateMerkleRoot -i ./blockchain_scripts/merkle/merkleDistributor/grants.murmuration.json > ./blockchain_scripts/merkle/merkleDistributor/merkleDistributorInfo.murmuration.json",
"deploy-for-client-test": "npx hardhat deploy --export-all deployments/all_dev.json",
"generate-merkle-distributor-grants:local": "node --require hardhat/register ./blockchain_scripts/merkle/merkleDistributor/generateGrantsFromTemplate -i ./blockchain_scripts/merkle/merkleDistributor/grants.dev.template.json > ./blockchain_scripts/merkle/merkleDistributor/grants.dev.json",
"generate-merkle-distributor-grants:client-test": "node --require hardhat/register ./blockchain_scripts/merkle/merkleDistributor/generateGrantsFromTemplate -i ./blockchain_scripts/merkle/merkleDistributor/grants.dev.template.json > ./blockchain_scripts/merkle/merkleDistributor/grants.client_test.json",
"generate-merkle-distributor-root:local": "npm run generate-merkle-distributor-grants:local && node --require hardhat/register ./blockchain_scripts/merkle/merkleDistributor/generateMerkleRoot -i ./blockchain_scripts/merkle/merkleDistributor/grants.dev.json > ./blockchain_scripts/merkle/merkleDistributor/merkleDistributorInfo.dev.json",
"generate-merkle-distributor-root:murmuration": "npm run generate-merkle-distributor-root:local",
"generate-merkle-distributor-root:client-test": "MERKLE_DISTRIBUTOR_GRANT_RECIPIENTS=0x0000000000000000000000000000000000000000 npm run generate-merkle-distributor-grants:client-test && node --require hardhat/register ./blockchain_scripts/merkle/merkleDistributor/generateMerkleRoot -i ./blockchain_scripts/merkle/merkleDistributor/grants.client_test.json > ./blockchain_scripts/merkle/merkleDistributor/merkleDistributorInfo.client_test.json",
"deploy-for-client-test": "npm run generate-merkle-distributor-root:client-test && MERKLE_DISTRIBUTOR_INFO_PATH=./blockchain_scripts/merkle/merkleDistributor/merkleDistributorInfo.client_test.json npx hardhat deploy --export-all deployments/all_client_test.json",
"lint": "eslint --resolve-plugins-relative-to=. .",
"lint:fix": "eslint --resolve-plugins-relative-to=. . --fix && prettier . --write && solhint 'contracts/**/*.sol' --fix",
"docs": "npx solidity-docgen && rm -rf docs/test",
Expand Down

0 comments on commit 63baf9b

Please sign in to comment.