Skip to content

Commit

Permalink
Update deploy script for permissioned protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
bricestacey committed Dec 9, 2022
1 parent 9953ca8 commit 49a688d
Showing 1 changed file with 121 additions and 37 deletions.
158 changes: 121 additions & 37 deletions scripts/deploy.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,19 +18,42 @@ async function main() {
usdcAddress = usdc.address;
}

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

// Deploy ServiceConfiguration
const ServiceConfiguration = await ethers.getContractFactory(
"PermissionedServiceConfiguration"
"PermissionedServiceConfiguration",
admin
);
const serviceConfiguration = await upgrades.deployProxy(
ServiceConfiguration,
{ kind: "uups" }
);
const serviceConfiguration = await ServiceConfiguration.deploy();
await serviceConfiguration.deployed();
console.log(
`PermissionedServiceConfiguration deployed to ${serviceConfiguration.address}`
`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 ToSAcceptanceRegistry
const ToSAcceptanceRegistry = await ethers.getContractFactory(
Expand Down Expand Up @@ -65,12 +88,12 @@ async function main() {

// Deploy PoolAdminAccessControl
const PoolAdminAccessControl = await ethers.getContractFactory(
"PoolAdminAccessControl"
"PoolAdminAccessControl",
admin
);
const poolAdminAccessControl = await PoolAdminAccessControl.deploy(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
serviceConfiguration.address
const poolAdminAccessControl = await upgrades.deployProxy(
PoolAdminAccessControl,
{ kind: "uups" }
);
await poolAdminAccessControl.deployed();
console.log(
Expand All @@ -86,11 +109,13 @@ async function main() {
// 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 PoolAccessControlFactory
Expand All @@ -104,15 +129,20 @@ async function main() {
console.log(
`PoolAccessControlFactory deployed to ${poolAccessControlFactory.address}`
);
const PoolAccessControl = await ethers.getContractFactory(
"PoolAccessControl"
);
const poolAccessControl = await PoolAccessControl.deploy();
await poolAccessControl.deployed();
console.log(`PoolAccessControl deployed to ${poolAccessControl.address}`);
await poolAccessControlFactory
.connect(deployer)
.setImplementation(poolAccessControl.address);
console.log(`PoolAccessControl set as implementation for its factory`);

// Deploy WithdrawControllerFactory
const WithdrawControllerFactory = await ethers.getContractFactory(
"WithdrawControllerFactory",
{
libraries: {
PoolLib: poolLib.address
}
}
"WithdrawControllerFactory"
);
const withdrawControllerFactory = await WithdrawControllerFactory.deploy(
serviceConfiguration.address
Expand All @@ -121,32 +151,51 @@ async function main() {
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}`
);
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(
"PermissionedPoolFactory",
{
libraries: {
PoolLib: poolLib.address
}
}
{}
);
const poolFactory = await PoolFactory.deploy(
serviceConfiguration.address,
Expand All @@ -155,20 +204,55 @@ async function main() {
poolAccessControlFactory.address
);
await poolFactory.deployed();
console.log(`PermissionedPoolFactory deployed to ${poolFactory.address}`);
console.log(`PoolFactory deployed to ${poolFactory.address}`);
const Pool = await ethers.getContractFactory("PermissionedPool", {
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(
"PermissionedLoanFactory",
{
libraries: {
LoanLib: loanLib.address
}
}
);
const LoanFactory = await ethers.getContractFactory("PermissionLoanFactory");
const loanFactory = await LoanFactory.deploy(serviceConfiguration.address);
await loanFactory.deployed();
console.log(`PermissionedLoanFactory deployed to ${loanFactory.address}`);
console.log(`LoanFactory deployed to ${loanFactory.address}`);

const Loan = await ethers.getContractFactory("PermissionedLoan", {
libraries: {
LoanLib: loanLib.address
}
});
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`);

// 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

0 comments on commit 49a688d

Please sign in to comment.