Skip to content

Commit

Permalink
Spider multiple markets (compound-finance#498)
Browse files Browse the repository at this point in the history
* Spider multiple deployments on a network

* update scenario bases to work with multiple deployments on a chain

* post rebase clean-up

* remove unnecessary type export

* lint

* restore deployments/development

* lint

* use base.network to determine if development

* move mainnet/usdc files

* move /development to /hardhat
  • Loading branch information
scott-silver authored Aug 4, 2022
1 parent fcf5188 commit ef4248e
Show file tree
Hide file tree
Showing 48 changed files with 334 additions and 232 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/deploy-market.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
options:
- fuji
- kovan
deployment:
description: Deployment Name (e.g. "usdc")
required: true
simulate:
type: boolean
description: Simulate
Expand Down Expand Up @@ -39,7 +42,7 @@ jobs:
run: yarn tsc

- name: Run Deploy
run: yarn hardhat deploy --network ${{ github.event.inputs.network }} ${{ fromJSON('["", "--simulate"]')[github.event.inputs.simulate == 'true'] }}
run: yarn hardhat deploy --network ${{ github.event.inputs.network }} --deployment ${{ github.event.inputs.deployment }} ${{ fromJSON('["", "--simulate"]')[github.event.inputs.simulate == 'true'] }}
env:
ETH_PK: ${{ github.event.inputs.eth_pk }}
DEBUG: true
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/enact-migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
options:
- fuji
- kovan
deployment:
description: Deployment Name (e.g. "usdc")
required: true
migration:
description: Migration Name
required: true
Expand Down Expand Up @@ -48,10 +51,10 @@ jobs:
with:
workflow: prepare-migration.yml
run_id: ${{ github.event.inputs.run_id }}
name: ${{ github.event.inputs.network }}-${{ github.event.inputs.migration }}
path: deployments/${{ github.event.inputs.network }}/artifacts/
name: ${{ github.event.inputs.network }}-${{ github.event.inputs.deployment }}-${{ github.event.inputs.migration }}
path: deployments/${{ github.event.inputs.network }}/${{ github.event.inputs.deployment }}/artifacts/

- name: Run Enact Migration
run: yarn hardhat migrate --network ${{ github.event.inputs.network }} --enact --overwrite ${{ fromJSON('["", "--simulate"]')[github.event.inputs.simulate == 'true'] }} ${{ github.event.inputs.migration }}
run: yarn hardhat migrate --network ${{ github.event.inputs.network }} --deployment ${{ github.event.inputs.deployment }} --enact --overwrite ${{ fromJSON('["", "--simulate"]')[github.event.inputs.simulate == 'true'] }} ${{ github.event.inputs.migration }}
env:
ETH_PK: ${{ github.event.inputs.eth_pk }}
9 changes: 6 additions & 3 deletions .github/workflows/prepare-migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
options:
- fuji
- kovan
deployment:
description: Deployment Name (e.g. "usdc")
required: true
migration:
description: Migration Name
required: true
Expand Down Expand Up @@ -42,13 +45,13 @@ jobs:
run: yarn tsc

- name: Run Prepare Migration
run: yarn hardhat migrate --network ${{ github.event.inputs.network }} --prepare --overwrite ${{ fromJSON('["", "--simulate"]')[github.event.inputs.simulate == 'true'] }} ${{ github.event.inputs.migration }}
run: yarn hardhat migrate --network ${{ github.event.inputs.network }} --deployment ${{ github.event.inputs.deployment }} --prepare --overwrite ${{ fromJSON('["", "--simulate"]')[github.event.inputs.simulate == 'true'] }} ${{ github.event.inputs.migration }}
env:
ETH_PK: ${{ github.event.inputs.eth_pk }}
DEBUG: true

- uses: actions/upload-artifact@v2 # upload test results
if: success() || failure() # run this step even if previous step failed
with:
name: ${{ github.event.inputs.network }}-${{ github.event.inputs.migration }}
path: deployments/${{ github.event.inputs.network }}/artifacts/${{ github.event.inputs.migration }}.json
name: ${{ github.event.inputs.network }}-${{ github.event.inputs.deployment }}-${{ github.event.inputs.migration }}
path: deployments/${{ github.event.inputs.network }}/${{ github.event.inputs.deployment }}/artifacts/${{ github.event.inputs.migration }}.json
15 changes: 7 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ artifacts/
build/
cache/
dist/
deployments/hardhat
deployments/*/artifacts
deployments/*/cache
deployments/*/contracts
deployments/*/verify
deployments/*/aliases.json
deployments/*/pointers.json
deployments/*/proxies.json
deployments/*/*/artifacts
deployments/*/*/cache
deployments/*/*/contracts
deployments/*/*/verify
deployments/*/*/aliases.json
deployments/*/*/pointers.json
deployments/*/*/proxies.json

.env
coverage/
Expand Down
14 changes: 7 additions & 7 deletions MIGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Migrations are simple scripts which deploy or modify contracts. The goal of migr
To create a new migration, run:

```sh
yarn hardhat gen:migration --network kovan my_migration
yarn hardhat gen:migration --network kovan --deployment usdc my_migration
```

This will create a new file, such as `deployments/kovan/migrations/164443237_my_migration.ts` with a base migration script. There are currently two steps to a migration script, but this is likely to change soon:
This will create a new file, such as `deployments/kovan/usdc/migrations/164443237_my_migration.ts` with a base migration script. There are currently two steps to a migration script, but this is likely to change soon:

1. Prepare: steps used to create artifacts, such as new on-chain contracts. The output from this step is stored (e.g. "NewCometImplementation: 0x...")
2. Enact: steps used to make these artifacts current, such as upgrading the proxy to the address from the previous step.
Expand All @@ -21,25 +21,25 @@ This will create a new file, such as `deployments/kovan/migrations/164443237_my_
You can run the preparation for a migration locally via:

```sh
yarn hardhat migrate --network kovan --prepare 164443237_my_migration
yarn hardhat migrate --network kovan --deployment usdc --prepare 164443237_my_migration
```

or the enactment via:

```sh
yarn hardhat migrate --network kovan --enact 164443237_my_migration
yarn hardhat migrate --network kovan --deployment usdc --enact 164443237_my_migration
```

or both preparation and enactment via:

```sh
yarn hardhat migrate --network kovan --prepare --enact 164443237_my_migration
yarn hardhat migrate --network kovan --deployment usdc --prepare --enact 164443237_my_migration
```

Also, you can simulate either of the previous steps to see what effect they would have without actually modifying the on-chain state:

```sh
yarn hardhat migrate --network kovan --prepare --simulate 164443237_my_migration
yarn hardhat migrate --network kovan --deployment usdc --prepare --simulate 164443237_my_migration
```

## Running a Migration in GitHub
Expand All @@ -48,4 +48,4 @@ The preferred way to run a migration is in GitHub, via manual workflow dispatch.

## Migration Artifacts

After preparation, a migration stores some artifacts under `deployments/kovan/artifacts/164443237_my_migration.json`. These will be loaded and can be referenced in the enact step of that migration.
After preparation, a migration stores some artifacts under `deployments/kovan/usdc/artifacts/164443237_my_migration.json`. These will be loaded and can be referenced in the enact step of that migration.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ This is just a prototype and it currently pulls relevant contracts for V2.

> Note: Make sure $ETHERSCAN_KEY is set as an env variable.
`npx hardhat spider --network mainnet`
`npx hardhat spider --network mainnet --deployment usdc`

#### Delete artifacts

Expand All @@ -169,7 +169,7 @@ The spider script uses configuration from two files to start its crawl:
- `roots.json`
- `relations.json`

Both these contracts are committed to the repo under `deployments/<chain>/<file>.json`. The `roots.json` config contains the address of the root contract for spider to start crawling from. The `relations.json` config defines all the different relationships and rules that spider will follow when crawling. The following section will go over in detail the set of rules defined in `relations.json`.
Both these contracts are committed to the repo under `deployments/<network>/<deployment>/<file>.json`. The `roots.json` config contains the address of the root contract for spider to start crawling from. The `relations.json` config defines all the different relationships and rules that spider will follow when crawling. The following section will go over in detail the set of rules defined in `relations.json`.

#### Defining relations

Expand All @@ -191,11 +191,11 @@ For more information, see [SCENARIO.md](./SCENARIO.md).

XXX explain/get to
deploying a new root contract?
deployments/${network}/${market}/deploy.ts
deployments/${network}/${deployment}/deploy.ts
open PR, run `deploy` workflow through CI
will commit `deployments/` diffs to branch
otherwise
deployments/${network}/${market}/migrations/XXX.ts
deployments/${network}/${deployment}/migrations/XXX.ts
open PR
if prepare step
run `prepare-migration` workflow through CI
Expand All @@ -216,12 +216,12 @@ New deployment?
XXX simplify to above

1. run `1644388553_deploy_kovan` migration, `prepare` step
2. update `deployments/kovan/roots.json` with the new roots from step 1
2. update `deployments/kovan/<deployment>/roots.json` with the new roots from step 1
3. run `1649108513_upgrade_timelock_and_set_up_governor` migration, `prepare` step
4. run `1649108513_upgrade_timelock_and_set_up_governor` migration, `enact` step
5. find the proposal ID step from 4; manually execute the proposal via the newly-deployed Governor
6. run `1651257129_bulker_and_rewards` migration, `prepare` step
7. update `deployments/kovan/roots.json` with the rewards and bulker roots from step 6
7. update `deployments/kovan/<deployment>/roots.json` with the rewards and bulker roots from step 6
8. run `1653357106_mint_to_fauceteer` migration, `prepare` step
9. run `1653512186_seed_rewards_with_comp`, `prepare` step
10. run `1653512186_seed_rewards_with_comp`, `enact` step
Expand All @@ -230,12 +230,12 @@ XXX simplify to above
#### Fuji

1. run `1644432723_deploy_fuji`, `prepare` step
2. update `deployments/fuji/roots.json` with new roots from step 1
2. update `deployments/fuji/<deployment>/roots.json` with new roots from step 1
3. run `1649117302_upgrade_timelock_and_set_up_governor`, `prepare` step
4. run `1649117302_upgrade_timelock_and_set_up_governor`, `enact` step
5. find the proposal ID step from 4; manually execute the proposal via the newly-deployed Governor
6. run `1651257139_rewards`, `prepare` step
7. update `deployments/fuji/roots.json` with new rewards root from step 6
7. update `deployments/fuji/<deployment>/roots.json` with new rewards root from step 6
8. run `1653431603_mint_to_fauceteer`, `prepare` step

#### Other considerations
Expand All @@ -252,7 +252,7 @@ Uniswap for a profit.
To run the bot, you'll need the address of a deployed version of the Liquidator
contract (or you can deploy a new instance of it yourself):

`LIQUIDATOR_ADDRESS="0xABC..." yarn liquidation-bot`
`LIQUIDATOR_ADDRESS="0xABC..." DEPLOYMENT="usdc" yarn liquidation-bot --network kovan`

Initiating transactions this way via the public mempool will
[almost certainly get frontrun](https://youtu.be/UZ-NNd6yjFM), but you might be
Expand Down
File renamed without changes.
10 changes: 4 additions & 6 deletions deployments/fuji/deploy.ts → deployments/fuji/usdc/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { DeploymentManager } from '../../plugins/deployment_manager/DeploymentManager';
import { migration } from '../../plugins/deployment_manager/Migration';
import { deployComet } from '../../src/deploy';
import { exp, wait } from '../../test/helpers';
import { DeploymentManager } from '../../../plugins/deployment_manager/DeploymentManager';
import { exp, wait } from '../../../test/helpers';
import {
Fauceteer,
Fauceteer__factory,
ProxyAdmin,
ProxyAdmin__factory
} from '../../build/types';
} from '../../../build/types';
import { Contract } from 'ethers';
import { debug } from '../../plugins/deployment_manager/Utils';
import { debug } from '../../../plugins/deployment_manager/Utils';

let cloneNetwork = 'avalanche';
let cloneAddr = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers';
import { CometInterface, CometRewards, ERC20, GovernorSimple, ProxyAdmin, SimpleTimelock } from '../../../build/types';
import { DeploymentManager } from '../../../plugins/deployment_manager/DeploymentManager';
import { migration } from '../../../plugins/deployment_manager/Migration';
import { CometInterface, CometRewards, ERC20, GovernorSimple, ProxyAdmin, SimpleTimelock } from '../../../../build/types';
import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager';
import { migration } from '../../../../plugins/deployment_manager/Migration';

interface Vars { };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"configurator": "0x40d84100b3907d10bee625b6603aba9b7e23932e",
"fauceteer": "0x3C9360273195fBB0077C999eFa67b347C7A56b7f",
"rewards": "0x77084a315C6D4401D097D9cE149136783106E6AA"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DeploymentManager } from '../../plugins/deployment_manager/DeploymentManager';
import { DeploymentManager } from '../../../plugins/deployment_manager/DeploymentManager';
import {
FaucetToken,
FaucetToken__factory,
SimplePriceFeed,
SimplePriceFeed__factory,
} from '../../build/types';
import { deployComet } from '../../src/deploy';
} from '../../../build/types';
import { deployComet } from '../../../src/deploy';

// XXX clean this all up further, but minimize changes for now on first pass refactor

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions deployments/kovan/deploy.ts → deployments/kovan/usdc/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { DeploymentManager } from '../../plugins/deployment_manager/DeploymentManager';
import { deployComet } from '../../src/deploy';
import { exp, wait } from '../../test/helpers';
import { DeploymentManager } from '../../../plugins/deployment_manager/DeploymentManager';
import { deployComet } from '../../../src/deploy';
import { exp, wait } from '../../../test/helpers';
import {
Bulker,
Bulker__factory,
Fauceteer,
Fauceteer__factory,
ProxyAdmin,
ProxyAdmin__factory,
} from '../../build/types';
} from '../../../build/types';
import { Contract } from 'ethers';
import { debug } from '../../plugins/deployment_manager/Utils';
import { debug } from '../../../plugins/deployment_manager/Utils';

let cloneNetwork = 'mainnet';
let cloneAddr = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CometInterface, CometRewards, ERC20, GovernorSimple, ProxyAdmin, SimpleTimelock } from '../../../build/types';
import { DeploymentManager } from '../../../plugins/deployment_manager/DeploymentManager';
import { migration } from '../../../plugins/deployment_manager/Migration';
import { debug } from '../../../plugins/deployment_manager/Utils';
import { wait } from '../../../test/helpers';
import { CometInterface, CometRewards, ERC20, GovernorSimple, ProxyAdmin, SimpleTimelock } from '../../../../build/types';
import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager';
import { migration } from '../../../../plugins/deployment_manager/Migration';
import { debug } from '../../../../plugins/deployment_manager/Utils';
import { wait } from '../../../../test/helpers';

interface Vars { };

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DeploymentManager } from '../../plugins/deployment_manager/DeploymentManager';
import { deployNetworkComet } from '../../src/deploy/Network';
import { DeploymentManager } from '../../../plugins/deployment_manager/DeploymentManager';
import { deployNetworkComet } from '../../../src/deploy/Network';
import { Contract } from 'ethers';
import { debug } from '../../plugins/deployment_manager/Utils';
import { Bulker, Bulker__factory } from '../../build/types';
import { debug } from '../../../plugins/deployment_manager/Utils';
import { Bulker, Bulker__factory } from '../../../build/types';

interface Vars {
comet: string,
Expand Down
19 changes: 10 additions & 9 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,24 @@ const config: HardhatUserConfig = {
bases: [
{
name: 'mainnet',
chainId: 1,
url: getDefaultProviderURL('mainnet'),
network: 'mainnet',
deployment: 'usdc',
allocation: 0.1, // eth
},
{
name: 'development',
network: 'hardhat',
deployment: 'dai'
},
{
name: 'kovan',
chainId: 42,
url: getDefaultProviderURL('kovan'),
allocation: 0.1, // eth
name: 'fuji',
network: 'fuji',
deployment: 'usdc'
},
{
name: 'fuji',
chainId: 43113,
url: 'https://api.avax-test.network/ext/bc/C/rpc',
name: 'kovan',
network: 'kovan',
deployment: 'usdc',
},
],
},
Expand Down
6 changes: 4 additions & 2 deletions plugins/deployment_manager/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ type CacheMap = Map<string, any | CacheMap>;

export class Cache {
cache: CacheMap;
network: string;
deployment: string;
deploymentDir: string;
writeCacheToDisk: boolean;

constructor(deployment: string, writeCacheToDisk?: boolean, deploymentDir?: string) {
constructor(network: string, deployment: string, writeCacheToDisk?: boolean, deploymentDir?: string) {
this.cache = new Map(); // todo cache config?
this.network = network;
this.deployment = deployment;
this.deploymentDir = deploymentDir ?? nodepath.join(process.cwd(), 'deployments');
this.writeCacheToDisk = writeCacheToDisk ?? false;
Expand All @@ -61,7 +63,7 @@ export class Cache {
} else if (Array.isArray(spec)) {
return spec.map((s) => s.toLowerCase());
} else if (spec.hasOwnProperty('rel')) {
return [this.deployment, ...this.getPath(spec.rel)];
return [this.network, this.deployment, ...this.getPath(spec.rel)];
}
}

Expand Down
Loading

0 comments on commit ef4248e

Please sign in to comment.