Skip to content

Commit

Permalink
Update permissionless deploy script (#144)
Browse files Browse the repository at this point in the history
* Update permissionless deploy script

* Update deploy-permissionless script to support Goerli

* Add console.log

* Add .env information
  • Loading branch information
bricestacey authored Dec 9, 2022
1 parent f458dfb commit fc06499
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GOERLI_URL=
GOERLI_ADMIN=
GOERLI_OPERATOR=
GOERLI_DEPLOYER=
GOERLI_PAUSER=
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ This repository contains the contracts for the Perimeter protocol.
npm install
```

Copy .env.example and update with appropriate values

```sh
cp .env.example .env
```

## Running a node

```sh
Expand Down
13 changes: 11 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import "hardhat-contract-sizer";
import "./tasks/serviceConfiguration";
import "./tasks/tosAcceptanceRegistry";
import "solidity-docgen";
import * as dotenv from "dotenv";
dotenv.config();

type ExtendedHardhatUserConfig = {
networks: {
Expand Down Expand Up @@ -33,8 +35,15 @@ const config: HardhatUserConfig | ExtendedHardhatUserConfig = {
usdcAddress: undefined
},
goerli: {
url: "",
usdcAddress: "0x07865c6e87b9f70255377e024ace6630c1eaa37f"
chainId: 5,
url: process.env.GOERLI_URL ?? "",
usdcAddress: "0x07865c6e87b9f70255377e024ace6630c1eaa37f",
accounts: [
process.env.GOERLI_ADMIN!,
process.env.GOERLI_OPERATOR!,
process.env.GOERLI_DEPLOYER!,
process.env.GOERLI_PAUSER!
].filter((x) => x)
}
},
docgen: {
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
"solidity-docgen": "^0.6.0-beta.32",
"typescript": "^4.8.2",
"uuid": "^9.0.0"
},
"dependencies": {
"dotenv": "^16.0.3"
}
}
130 changes: 100 additions & 30 deletions scripts/deploy-permissionless.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers } from "hardhat";
import { ethers, upgrades } from "hardhat";
import hre from "hardhat";

type ExtendedHreNetworkConfig = typeof hre.network.config & {
Expand All @@ -18,94 +18,164 @@ async function main() {
usdcAddress = usdc.address;
}

const [admin, operator, deployer, pauser] = await ethers.getSigners();

// Deploy ServiceConfiguration
const ServiceConfiguration = await ethers.getContractFactory(
"ServiceConfiguration"
"ServiceConfiguration",
admin
);
const serviceConfiguration = await upgrades.deployProxy(
ServiceConfiguration,
{ kind: "uups" }
);
const serviceConfiguration = await ServiceConfiguration.deploy();
await serviceConfiguration.deployed();

console.log(
`ServiceConfiguration deployed to ${serviceConfiguration.address}`
);

// Set USDC as a liquidity asset for the protocol
await serviceConfiguration.setLiquidityAsset(usdcAddress, true);
console.log(`Updated ServiceConfiguration to add USDC as a liquidity asset`);
// Grant operator role
let tx = await serviceConfiguration
.connect(admin)
.grantRole(serviceConfiguration.OPERATOR_ROLE(), operator.address);
await tx.wait();
console.log(`Granted operator role to ${operator.address}`);

// Grant pauser role
tx = await serviceConfiguration
.connect(admin)
.grantRole(serviceConfiguration.PAUSER_ROLE(), pauser.address);
await tx.wait();
console.log(`Granted pauser role to ${pauser.address}`);

// Grant deployer role
tx = await serviceConfiguration
.connect(admin)
.grantRole(serviceConfiguration.DEPLOYER_ROLE(), deployer.address);
await tx.wait();
console.log(`Granted deployer role to ${deployer.address}`);

// Deploy PoolLib
const PoolLib = await ethers.getContractFactory("PoolLib");
const poolLib = await PoolLib.deploy();

await poolLib.deployed();
console.log(`PoolLib deployed to ${poolLib.address}`);

// Deploy LoanLib
const LoanLib = await ethers.getContractFactory("LoanLib");
const loanLib = await LoanLib.deploy();

await loanLib.deployed();
console.log(`LoanLib deployed to ${loanLib.address}`);

// Deploy WithdrawControllerFactory
const WithdrawControllerFactory = await ethers.getContractFactory(
"WithdrawControllerFactory",
{
libraries: {
PoolLib: poolLib.address
}
}
"WithdrawControllerFactory"
);
const withdrawControllerFactory = await WithdrawControllerFactory.deploy(
serviceConfiguration.address
);
await withdrawControllerFactory.deployed();

console.log(
`WithdrawControllerFactory deployed to ${withdrawControllerFactory.address}`
);

// Deploy PoolControllerFactory
const PoolControllerFactory = await ethers.getContractFactory(
"PoolControllerFactory",
const WithdrawController = await ethers.getContractFactory(
"WithdrawController",
{
libraries: {
PoolLib: poolLib.address
}
}
);
const withdrawController = await WithdrawController.deploy();
await withdrawController.deployed();
console.log(`WithdrawController deployed to ${withdrawController.address}`);
await withdrawControllerFactory
.connect(deployer)
.setImplementation(withdrawController.address);
console.log(`WithdrawController set as implementation for its factory`);

// Deploy PoolControllerFactory
const PoolControllerFactory = await ethers.getContractFactory(
"PoolControllerFactory"
);
const poolControllerFactory = await PoolControllerFactory.deploy(
serviceConfiguration.address
);
await poolControllerFactory.deployed();

console.log(
`PoolControllerFactory deployed to ${poolControllerFactory.address}`
);

// Deploy PoolFactory
const PoolFactory = await ethers.getContractFactory("PoolFactory", {
const PoolController = await ethers.getContractFactory("PoolController", {
libraries: {
PoolLib: poolLib.address
}
});
const poolController = await PoolController.deploy();
await poolController.deployed();
console.log(`PoolController deployed to ${poolController.address}`);
tx = await poolControllerFactory
.connect(deployer)
.setImplementation(poolController.address);
await tx.wait();
console.log(`PoolController set as implementation for its factory`);

// Deploy PoolFactory
const PoolFactory = await ethers.getContractFactory("PoolFactory", {});
const poolFactory = await PoolFactory.deploy(
usdcAddress,
serviceConfiguration.address,
withdrawControllerFactory.address,
poolControllerFactory.address
);
await poolFactory.deployed();

console.log(`PoolFactory deployed to ${poolFactory.address}`);
const Pool = await ethers.getContractFactory("Pool", {
libraries: {
PoolLib: poolLib.address
}
});
const pool = await Pool.deploy();
await pool.deployed();
console.log(`Pool deployed to ${pool.address}`);
tx = await poolFactory.connect(deployer).setImplementation(pool.address);
await tx.wait();
console.log(`Pool set as imlementation for its factory`);

// Deploy LoanFactory
const LoanFactory = await ethers.getContractFactory("LoanFactory", {
const LoanFactory = await ethers.getContractFactory("LoanFactory");
const loanFactory = await LoanFactory.deploy(serviceConfiguration.address);
await loanFactory.deployed();
console.log(`LoanFactory deployed to ${loanFactory.address}`);

const Loan = await ethers.getContractFactory("Loan", {
libraries: {
LoanLib: loanLib.address
}
});
const loanFactory = await LoanFactory.deploy(serviceConfiguration.address);
await loanFactory.deployed();
const loan = await Loan.deploy();
await loan.deployed();
console.log(`Loan deployed to ${loan.address}`);
await loanFactory.connect(deployer).setImplementation(loan.address);
console.log(`Loan set as implementation for its Factory`);

// Setup LoanFactory
tx = await serviceConfiguration
.connect(operator)
.setLoanFactory(loanFactory.address, true);
await tx.wait();
console.log(`ServiceConfiguration: set LoanFactory as valid`);

console.log(`LoanFactory deployed to ${loanFactory.address}`);
// Set USDC as a liquidity asset for the protocol
tx = await serviceConfiguration
.connect(operator)
.setLiquidityAsset(usdcAddress, true);
await tx.wait();
console.log(`ServiceConfiguration: set USDC as a liquidity asset`);

// Set first loss minimum to $10,000
tx = await serviceConfiguration
.connect(operator)
.setFirstLossMinimum(usdcAddress, 10_000_000000);
console.log(`ServiceConfiguration: set USDC first loss minimum to $10,000`);
}

// We recommend this pattern to be able to use async/await everywhere
Expand Down
4 changes: 3 additions & 1 deletion test/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ export function findEventByName(receipt: any, name: string) {
* Get commonly-used signers.
*/
export async function getCommonSigners() {
// To maintain compatability across networks, order should match what is
// defined in the hardhat config
const [
operator,
admin,
operator,
deployer,
pauser,
poolAdmin,
Expand Down

0 comments on commit fc06499

Please sign in to comment.