8000 Refactor deploy to support second markets by jflatow · Pull Request #639 · compound-finance/comet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor deploy to support second markets #639

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

Merged
merged 2 commits into from
Dec 29, 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
4 changes: 2 additions & 2 deletions deployments/fuji/usdc/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
"borrowCF": 0.7,
"liquidateCF": 0.75,
"liquidationFactor": 0.93,
"supplyCap": "35000e8"
"supplyCap": "35000"
},
"WAVAX": {
"priceFeed": "0x5498BB86BC934c8D34FDA08E81D444153d0D06aD",
"decimals": "18",
"borrowCF": 0.82,
"liquidateCF": 0.85,
"liquidationFactor": 0.93,
"supplyCap": "1000000e18"
"supplyCap": "1000000"
}
}
}
6 changes: 3 additions & 3 deletions deployments/goerli/usdc/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@
"borrowCF": 0.65,
"liquidateCF": 0.7,
"liquidationFactor": 0.92,
"supplyCap": "500000e18"
"supplyCap": "500000"
},
"WBTC": {
"priceFeed": "0xA39434A63A52E749F02807ae27335515BA4b07F7",
"decimals": "8",
"borrowCF": 0.7,
"liquidateCF": 0.75,
"liquidationFactor": 0.93,
"supplyCap": "35000e8"
"supplyCap": "35000"
}, 10000
"WETH": {
"priceFeed": "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e",
"decimals": "18",
"borrowCF": 0.82,
"liquidateCF": 0.85,
"liquidationFactor": 0.93,
"supplyCap": "1000000e18"
"supplyCap": "1000000"
}
}
}
10 changes: 5 additions & 5 deletions deployments/kovan/usdc/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,39 @@
"borrowCF": 0.65,
"liquidateCF": 0.7,
"liquidationFactor": 0.92,
"supplyCap": "500000e18"
"supplyCap": "500000"
},
"WBTC": {
"priceFeed": "0x6135b13325bfC4B00278B4abC5e20bbce2D6580e",
"decimals": "8",
"borrowCF": 0.7,
"liquidateCF": 0.75,
"liquidationFactor": 0.93,
"supplyCap": "35000e8"
"supplyCap": "35000"
},
"WETH": {
"priceFeed": "0x9326BFA02ADD2366b30bacB125260Af641031331",
"decimals": "18",
"borrowCF": 0.82,
"liquidateCF": 0.85,
"liquidationFactor": 0.93,
"supplyCap": "1000000e18"
"supplyCap": "1000000"
},
"UNI": {
"priceFeed": "0xDA5904BdBfB4EF12a3955aEcA103F51dc87c7C39",
"decimals": "18",
"borrowCF": 0.75,
"liquidateCF": 0.8,
"liquidationFactor": 0.92,
"supplyCap": "50000000e18"
"supplyCap": "50000000"
},
"LINK": {
"priceFeed": "0x396c5E36DD0a0F5a5D33dae44368D4193f69a1F0",
"decimals": "18",
"borrowCF": 0.75,
"liquidateCF": 0.8,
"liquidationFactor": 0.92,
"supplyCap": "50000000e18"
"supplyCap": "50000000"
}
}
}
10 changes: 5 additions & 5 deletions deployments/mainnet/usdc/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"borrowCF": 0.65,
"liquidateCF": 0.70,
"liquidationFactor": 0.93,
"supplyCap": "0e18"
"supplyCap": "0"
},
"WBTC": {
"address": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
Expand All @@ -43,7 +43,7 @@
"borrowCF": 0.70,
"liquidateCF": 0.77,
"liquidationFactor": 0.95,
"supplyCap": "0e8"
"supplyCap": "0"
},
"WETH": {
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
Expand All @@ -52,7 +52,7 @@
"borrowCF": 0.825,
"liquidateCF": 0.895,
"liquidationFactor": 0.95,
"supplyCap": "0e18"
"supplyCap": "0"
},
"UNI": {
"address": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
Expand All @@ -61,7 +61,7 @@
"borrowCF": 0.75,
"liquidateCF": 0.81,
"liquidationFactor": 0.93,
"supplyCap": "0e18"
"supplyCap": "0"
},
"LINK": {
"address": "0x514910771af9ca656af840dff83e8264ecf986ca",
Expand All @@ -70,7 +70,7 @@
"borrowCF": 0.79,
"liquidateCF": 0.85,
"liquidationFactor": 0.93,
"supplyCap": "0e18"
"supplyCap": "0"
}
}
}
1 change: 1 addition & 0 deletions deployments/mainnet/weth/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"baseBorrowSpeed": "0e15",
"baseMinForRewards": "1000000e6"
},
"rewardTokenAddress": "0xc00e94cb662c3520282e6f5717214004a7f26888",
"assets": {
"cbETH": {
"address": "0xBe9895146f7AF43049ca1c1AE358B0541Ea49704",
Expand Down
7 changes: 7 additions & 0 deletions deployments/mainnet/weth/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo
]
);

// Import shared contracts from cUSDCv3
const cometAdmin = await deploymentManager.fromDep('cometAdmin', 'mainnet', 'usdc');
const cometFactory = await deploymentManager.fromDep('cometFactory', 'mainnet', 'usdc');
const $configuratorImpl = await deploymentManager.fromDep('configurator:implementation', 'mainnet', 'usdc');
const configurator = await deploymentManager.fromDep('configurator', 'mainnet', 'usdc');
const rewards = await deploymentManager.fromDep('rewards', 'mainnet', 'usdc');

// Deploy all Comet-related contracts
const deployed = await deployComet(deploymentManager, deploySpec);
const { comet } = deployed;
Expand Down
8 changes: 4 additions & 4 deletions deployments/mumbai/usdc/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@
"borrowCF": 0.79,
"liquidateCF": 0.85,
"liquidationFactor": 0.93,
"supplyCap": "500000e18"
"supplyCap": "500000"
},
"WETH": {
"priceFeed": "0x0715A7794a1dc8e42615F059dD6e406A6594651A",
"decimals": "18",
"borrowCF": 0.82,
"liquidateCF": 0.85,
"liquidationFactor": 0.93,
"supplyCap": "1000000e18"
"supplyCap": "1000000"
},
"WBTC": {
"priceFeed": "0x007A22900a3B98143368Bd5906f8E17e9867581b",
"decimals": "8",
"borrowCF": 0.7,
"liquidateCF": 0.75,
"liquidationFactor": 0.93,
"supplyCap": "35000e8"
"supplyCap": "35000"
},
"WMATIC": {
"priceFeed": "0xd0D5e3DB44DE05E9F294BB0a3bEEaF030DE24Ada",
"decimals": "18",
"borrowCF": 0.82,
"liquidateCF": 0.85,
"liquidationFactor": 0.93,
"supplyCap": "1000000e18"
"supplyCap": "1000000"
}
}
}
6 changes: 6 additions & 0 deletions plugins/deployment_manager/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export class Cache {
this.writeCacheToDisk = writeCacheToDisk ?? false;
}

asDeployment(network: string, deployment: string): Cache {
const cache = new Cache(network, deployment, this.writeCacheToDisk, this.deploymentDir);
cache.cache = this.cache;
return cache;
}

private getPath(spec: FileSpec): string[] {
if (typeof spec === 'string') {
return [spec.toLowerCase()];
Expand Down
27 changes: 26 additions & 1 deletion plugins/deployment_manager/DeploymentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { Contract, providers } from 'ethers';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { Alias, Address, BuildFile, TraceFn } from './Types';
import { putAlias, storeAliases } from './Aliases';
import { getAliases, storeAliases, putAlias } from './Aliases';
import { Cache } from './Cache';
import { ContractMap } from './ContractMap';
import { DeployOpts, deploy, deployBuild } from './Deploy';
Expand Down Expand Up @@ -206,6 +206,25 @@ export class DeploymentManager {
return maybeExisting;
}

async fromDep<C extends Contract>(
alias: Alias,
network: string,
deployment: string,
otherAlias = alias
): Promise<C> {
const maybeExisting = await this.contract<C>(alias);
if (!maybeExisting) {
const trace = this.tracer();
const address = await this.readAlias(network, deployment, otherAlias);
const buildFile = await this.import(address, network);
const contract = getEthersContract<C>(address, buildFile, this.hre);
await this.putAlias(alias, contract);
trace(`Loaded ${buildFile.contract} from ${network}/${deployment}:${otherAlias} (${address}) as '${alias}'`);
return contract;
}
return maybeExisting;
}

/* Deploys a contract from Hardhat artifacts */
async _deploy<C extends Contract>(contractFile: string, deployArgs: any[], retries?: number): Promise<C> {
const contract = await this.retry(
Expand Down Expand Up @@ -294,6 +313,12 @@ export class DeploymentManager {
this.contractsCache.set(alias, contract);
}

/* Read an alias from another deployment */
async readAlias(network: string, deployment: string, alias: Alias): Promise<Address> {
const aliases = await getAliases(this.cache.asDeployment(network, deployment));
return aliases.get(alias);
}

/* Returns a memory-cached map of contracts indexed by alias.
* Note: this map is cached in-memory and updated when aliases change,
* so call this as often as you would like.
Expand Down
6 changes: 3 additions & 3 deletions plugins/scenario/utils/TokenSourcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface SourceTokenParameters {
amount: number | bigint;
asset: string;
address: string;
blacklist: string[] | undefined;
blacklist: string[];
}

export async function fetchQuery(
Expand Down Expand Up @@ -62,7 +62,7 @@ export async function sourceTokens({
} else if (amount.isNegative()) {
await removeTokens(dm, amount.abs(), asset, address);
} else {
await addTokens(dm, amount, asset, address, blacklist);
await addTokens(dm, amount, asset, address, [address].concat(blacklist));
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ async function addTokens(
amount: BigNumber,
asset: string,
address: string,
blacklist?: string[],
blacklist: string[],
block?: number,
offsetBlocks?: number,
MAX_SEARCH_BLOCKS = 40000,
Expand Down
2 changes: 2 additions & 0 deletions scenario/constraints/MigrationConstraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export class MigrationConstraint<T extends CometContext, R extends Requirements>
const solutions: Solution<T>[] = [];

for (const migrationList of subsets(await getMigrations(context, requirements))) {
if (migrationList.length == 0 && process.env['MIGRATIONS_ONLY'])
continue;
solutions.push(async function (ctx: T): Promise<T> {
const proposer = await ctx.getProposer();

Expand Down
26 changes: 7 additions & 19 deletions scenario/constraints/ModernConstraint.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
import { Constraint } from '../../plugins/scenario';
import { CometContext } from '../context/CometContext';
import { ProtocolConfiguration } from '../../src/deploy';
import { getFuzzedRequirements } from './Fuzzing';
import { Requirements } from './Requirements';

interface ModernConfig {
// Whether to upgrade or Comet config overrides to use for an upgrade
upgrade: ProtocolConfiguration;
}

async function getModernConfigs(context: CometContext, requirements: Requirements): Promise<ModernConfig[]> {
const currentConfig = await context.getConfiguration();
const fuzzedConfigs = getFuzzedRequirements(requirements).map((r) => ({
upgrade: r.upgrade && Object.assign({}, currentConfig, r.upgrade),
}));
return fuzzedConfigs;
}

export class ModernConstraint<T extends CometContext, R extends Requirements> implements Constraint<T, R> {
async solve(requirements: R, context: T) {
const configs = await getModernConfigs(context, requirements);
async solve(requirements: R, _context: T) {
const fuzzed = await getFuzzedRequirements(requirements);
const solutions = [];
for (const config of configs) {
if (config.upgrade) {
for (const req of fuzzed) {
if (req.upgrade) {
solutions.push(async function solution(ctx: T): Promise<T> {
return await ctx.upgrade(config.upgrade) as T; // It's been modified
const current = await ctx.getConfiguration();
const upgrade = Object.assign({}, current, req.upgrade);
return await ctx.upgrade(upgrade) as T; // It's been modified
});
}
}
Expand Down
1 change: 0 additions & 1 deletion scenario/constraints/UtilizationConstraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export class UtilizationConstraint<T extends CometContext, R extends Requirement
collateralNeeded = (collateralNeeded * 11n) / 10n; // add fudge factor

try {
// XXX sourceTokens can silently fail, which can somehow leave borrowActor unimpersonated and an approve failure...
await context.sourceTokens(collateralNeeded, collateralToken, borrowActor);
await collateralToken.approve(borrowActor, comet);
await borrowActor.safeSupplyAsset({ asset: collateralToken.address, amount: collateralNeeded });
Expand Down
Loading
0