Skip to content

Commit

Permalink
Porting in OZ clone (compound-finance#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
jflatow authored Apr 4, 2023
1 parent 518cea7 commit 7f796bf
Show file tree
Hide file tree
Showing 6 changed files with 573 additions and 13 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ This can also be used together with `--overwrite`, to produce the verification a
Make sure that the deploying address has a sufficient amount of the chain's
native asset (i.e. 2 ETH for Kovan, 2 AVAX for Fuji)

### Clone Multisig

The `clone-multisig` script can be used to clone the multisig and its configuration from an existing deployment, e.g.:

```bash
DST_NETWORK=optimism-goerli npx hardhat run scripts/clone-multisig.ts
```

### Liquidation Bot

This repo includes a contract (Liquidator.sol) that will absorb an underwater
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-etherscan';
import '@typechain/hardhat';
import 'hardhat-chai-matchers';
import 'hardhat-change-network';
import 'hardhat-contract-sizer';
import 'hardhat-cover';
import 'hardhat-gas-reporter';
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"@ethersproject/experimental": "^5.6.3",
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@nomiclabs/hardhat-etherscan": "3.0.0",
"@safe-global/safe-core-sdk": "^3.3.2",
"@safe-global/safe-ethers-lib": "^1.9.2",
"@typechain/ethers-v5": "^8.0.2",
"@typechain/hardhat": "^3.0.0",
"@types/chai": "^4.2.22",
Expand All @@ -68,10 +70,11 @@
"chalk": "^5.0.0",
"dotenv": "^10.0.0",
"eslint": "^8.12.0",
"ethers": "^5.7.1",
"ethers": "^5.7.2",
"fast-glob": "^3.2.7",
"hardhat": "https://github.com/jflatow/hardhat/releases/download/viaIR/hardhat-v2.12.0.tgz",
"hardhat-chai-matchers": "https://github.com/jflatow/hardhat/releases/download/viaIR/nomicfoundation-hardhat-chai-matchers-v1.0.4.tgz",
"hardhat-change-network": "^0.0.7",
"hardhat-contract-sizer": "^2.4.0",
"hardhat-cover": "compound-finance/hardhat-cover",
"hardhat-gas-reporter": "^1.0.7",
Expand Down
4 changes: 4 additions & 0 deletions plugins/scenario/utils/hreForBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { HARDHAT_PARAM_DEFINITIONS } from 'hardhat/internal/core/params/hardhat-
import { Environment } from 'hardhat/internal/core/runtime-environment';
import { ForkSpec } from '../World';
import { HttpNetworkUserConfig } from 'hardhat/types';
import { EthereumProvider } from "hardhat/types/provider";

/*
mimics https://github.com/nomiclabs/hardhat/blob/master/packages/hardhat-core/src/internal/lib/hardhat-lib.ts
Expand All @@ -24,11 +25,14 @@ additional packages that alter the HardhatRuntimeEnvironment interface.
ethers type extension: https://github.com/nomiclabs/hardhat/blob/master/packages/hardhat-ethers/src/internal/type-extensions.ts
waffle type extension: https://github.com/nomiclabs/hardhat/blob/master/packages/hardhat-waffle/src/type-extensions.ts
change network extension: https://github.com/dmihal/hardhat-change-network/blob/master/src/type-extensions.ts
*/
declare module 'hardhat/internal/core/runtime-environment' {
interface Environment {
waffle: any;
ethers: typeof ethers & HardhatEthersHelpers;
changeNetwork(newNetwork: string): void;
getProvider(newNetwork: string): EthereumProvider;
}
}

Expand Down
44 changes: 44 additions & 0 deletions scripts/clone-multisig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import hre from 'hardhat';
import { DeploymentManager } from '../plugins/deployment_manager/DeploymentManager';
import { SafeFactory } from '@safe-global/safe-core-sdk';
import EthersAdapter from '@safe-global/safe-ethers-lib';

const SRC_NETWORK = process.env['SRC_NETWORK'] ?? 'mainnet';
const DST_NETWORK = process.env['DST_NETWORK'] ?? 'hardhat';

async function main() {
await hre.changeNetwork(SRC_NETWORK);

const dm = new DeploymentManager(SRC_NETWORK, 'usdc', hre);

const signer_ = await dm.getSigner();
const comet = await dm.contract('comet');
const guardian = await comet.pauseGuardian();

// Get owners and threshold from existing multisig
const GnosisABI = [
{"constant":true,"inputs":[],"name":"getOwners","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},
{"constant":true,"inputs":[],"name":"getThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},
];
const GnosisSafeContract = new hre.ethers.Contract(guardian, GnosisABI, hre.ethers.provider);
const owners = await GnosisSafeContract.getOwners();
const threshold = await GnosisSafeContract.getThreshold();
const safeAccountConfig = { owners: owners, threshold: threshold};
console.log(safeAccountConfig);
console.log(guardian);

await hre.changeNetwork(DST_NETWORK);

const signer = await hre.ethers.provider.getSigner(signer_.address);
const ethAdapter = new EthersAdapter({ ethers: hre.ethers, signerOrProvider: signer });
const safeFactory = await SafeFactory.create({ ethAdapter: ethAdapter });
const safeSdk = await safeFactory.deploySafe({ safeAccountConfig });
console.log(safeSdk);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Loading

0 comments on commit 7f796bf

Please sign in to comment.