Skip to content
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

Add deploy script for permissioned and permissionless protocols #103

Merged
merged 12 commits into from
Nov 29, 2022
81 changes: 20 additions & 61 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,18 @@
import { HardhatUserConfig, task } from "hardhat/config";
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "hardhat-contract-sizer";
import { Contract, ContractFactory } from "ethers";
import "./tasks/serviceConfiguration";
import "./tasks/tosAcceptanceRegistry";

task("setPaused", "Pauses the protocol")
.addParam("address", "Address of the service configuration contract")
.addOptionalParam("paused", `"true" to pause, "false" to unpause`, "true")
.setAction(async (taskArgs, hre) => {
const ServiceConfiguration: ContractFactory =
await hre.ethers.getContractFactory("ServiceConfiguration");
const serviceConfiguration = ServiceConfiguration.attach(taskArgs.address);
const tx = await serviceConfiguration.setPaused(taskArgs.paused === "true");
const receipt = await tx.wait();
console.log("Transaction hash:", receipt.transactionHash);
});

task("setLiquidityAsset", "Set a token as a liquidity asset")
.addParam("address", "Address of the service configuration contract")
.addParam("token", "Address of the token")
.addOptionalParam("enabled", `"true" to enable, "false" to disable`)
.setAction(async (taskArgs, hre) => {
const ServiceConfiguration: ContractFactory =
await hre.ethers.getContractFactory("ServiceConfiguration");
const serviceConfiguration = ServiceConfiguration.attach(taskArgs.address);
const tx = await serviceConfiguration.setLiquidityAsset(
taskArgs.token,
taskArgs.enabled === "true"
);
const receipt = await tx.wait();
console.log("Transaction hash:", receipt.transactionHash);
});

task("setLoanFactory", "Set a loan factory")
.addParam("address", "Address of the service configuration contract")
.addParam("factory", "Address of the loan factory")
.addOptionalParam("enabled", `"true" to enable, "false" to disable`)
.setAction(async (taskArgs, hre) => {
const ServiceConfiguration: ContractFactory =
await hre.ethers.getContractFactory("ServiceConfiguration");
const serviceConfiguration = ServiceConfiguration.attach(taskArgs.address);
const tx = await serviceConfiguration.setLoanFactory(
taskArgs.factory,
taskArgs.enabled === "true"
);
const receipt = await tx.wait();
console.log("Transaction hash:", receipt.transactionHash);
});

task("setToSAcceptanceRegistry", "Set a ToS registry")
.addParam("address", "Address of the service configuration contract")
.addParam("registry", "Address of the ToS registry")
.setAction(async (taskArgs, hre) => {
const ServiceConfiguration: ContractFactory =
await hre.ethers.getContractFactory("ServiceConfiguration");
const serviceConfiguration = ServiceConfiguration.attach(taskArgs.address);
const tx = await serviceConfiguration.setToSAcceptanceRegistry(
taskArgs.registry
);
const receipt = await tx.wait();
console.log("Transaction hash:", receipt.transactionHash);
});
type ExtendedHardhatUserConfig = {
networks: {
[network: string]: {
usdcAddress: string | undefined;
};
};
};

const config: HardhatUserConfig = {
const config: HardhatUserConfig | ExtendedHardhatUserConfig = {
solidity: {
version: "0.8.16",
settings: {
Expand All @@ -73,7 +24,15 @@ const config: HardhatUserConfig = {
},
networks: {
hardhat: {
allowUnlimitedContractSize: true
allowUnlimitedContractSize: true,
usdcAddress: undefined
},
localhost: {
usdcAddress: undefined
},
goerli: {
url: "",
usdcAddress: "0x07865c6e87b9f70255377e024ace6630c1eaa37f"
}
}
};
Expand Down
110 changes: 110 additions & 0 deletions scripts/deploy-permissionless.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { ethers } from "hardhat";
import hre from "hardhat";

async function main() {
// The token we use for the liquidity asset must exist. If it is not defined, we'll deploy a mock token.
let usdcAddress = hre.network.config.usdcAddress;
if (!usdcAddress) {
const Usdc = await ethers.getContractFactory("MockERC20");
const usdc = await Usdc.deploy("USD Coin", "USDC", 6);
await usdc.deployed();
console.log(`Deployed mock USDC token to ${usdc.address}`);
usdcAddress = usdc.address;
}

// Deploy ServiceConfiguration
const ServiceConfiguration = await ethers.getContractFactory(
"ServiceConfiguration"
);
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`);

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

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

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

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

// Deploy WithdrawControllerFactory
const WithdrawControllerFactory = await ethers.getContractFactory(
"WithdrawControllerFactory",
{
libraries: {
PoolLib: poolLib.address
}
}
);
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",
{
libraries: {
PoolLib: poolLib.address
}
}
);
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", {
libraries: {
PoolLib: poolLib.address
}
});
const poolFactory = await PoolFactory.deploy(
usdcAddress,
withdrawControllerFactory.address,
poolControllerFactory.address
);
await poolFactory.deployed();

console.log(`PoolFactory deployed to ${poolFactory.address}`);

// Deploy LoanFactory
const LoanFactory = await ethers.getContractFactory("LoanFactory", {
libraries: {
LoanLib: loanLib.address
}
});
const loanFactory = await LoanFactory.deploy(serviceConfiguration.address);
await loanFactory.deployed();

console.log(`LoanFactory deployed to ${loanFactory.address}`);
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
153 changes: 151 additions & 2 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,164 @@
import { ethers } from "hardhat";
import hre from "hardhat";

async function main() {
// The token we use for the liquidity asset must exist. If it is not defined, we'll deploy a mock token.
let usdcAddress = hre.network.config.usdcAddress;
if (!usdcAddress) {
const Usdc = await ethers.getContractFactory("MockERC20");
const usdc = await Usdc.deploy("USD Coin", "USDC", 6);
await usdc.deployed();
console.log(`Deployed mock USDC token to ${usdc.address}`);
usdcAddress = usdc.address;
}

// Deploy ServiceConfiguration
const ServiceConfiguration = await ethers.getContractFactory(
"ServiceConfiguration"
"PermissionedServiceConfiguration"
);
const serviceConfiguration = await ServiceConfiguration.deploy();
await serviceConfiguration.deployed();
console.log(
`PermissionedServiceConfiguration 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`);

// Deploy ToSAcceptanceRegistry
const ToSAcceptanceRegistry = await ethers.getContractFactory(
"ToSAcceptanceRegistry"
);
const toSAcceptanceRegistry = await ToSAcceptanceRegistry.deploy(
serviceConfiguration.address
);
await toSAcceptanceRegistry.deployed();
console.log(
`ServiceConfiguration deployed to ${serviceConfiguration.address}`
`ToSAcceptanceRegistry deployed to ${toSAcceptanceRegistry.address}`
);

// Set ToSAcceptanceRegsitry URL
const TOS_ACCEPTANCE_REGISTRY_URL = "http://example.com"; // TODO update with real URL
const setTosUrlTx = await toSAcceptanceRegistry.updateTermsOfService(
TOS_ACCEPTANCE_REGISTRY_URL
);
await setTosUrlTx.wait();
console.log(
`ToSAcceptanceRegistry URL set to ${TOS_ACCEPTANCE_REGISTRY_URL}`
);

// Update ServiceConfiguration with the ToSAcceptanceRegistry
const setTosRegistryTx = await serviceConfiguration.setToSAcceptanceRegistry(
toSAcceptanceRegistry.address
);
await setTosRegistryTx.wait();
console.log(`ServiceConfiguration updated with new ToSAcceptanceRegistry`);

// Deploy PoolAdminAccessControl
const PoolAdminAccessControl = await ethers.getContractFactory(
"PoolAdminAccessControl"
);
const poolAdminAccessControl = await PoolAdminAccessControl.deploy(
serviceConfiguration.address
);
await poolAdminAccessControl.deployed();
console.log(
`PoolAdminAccess control deployed at ${poolAdminAccessControl.address}`
);

// Update ServiceConfigurtation with the PoolAdminAccessControl
await serviceConfiguration.setPoolAdminAccessControl(
poolAdminAccessControl.address
);
console.log("ServiceConfiguration updated with new PoolAdminAccessControl");

// Deploy PoolLib
const PoolLib = await ethers.getContractFactory("PoolLib");
const poolLib = await PoolLib.deploy();
console.log(`PoolLib deployed to ${poolLib.address}`);

// Deploy LoanLib
const LoanLib = await ethers.getContractFactory("LoanLib");
const loanLib = await LoanLib.deploy();
console.log(`LoanLib deployed to ${loanLib.address}`);

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

// Deploy WithdrawControllerFactory
const WithdrawControllerFactory = await ethers.getContractFactory(
"WithdrawControllerFactory",
{
libraries: {
PoolLib: poolLib.address
}
}
);
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",
{
libraries: {
PoolLib: poolLib.address
}
}
);
const poolControllerFactory = await PoolControllerFactory.deploy(
serviceConfiguration.address
);
await poolControllerFactory.deployed();
console.log(
`PoolControllerFactory deployed to ${poolControllerFactory.address}`
);

// Deploy PoolFactory
const PoolFactory = await ethers.getContractFactory(
"PermissionedPoolFactory",
{
libraries: {
PoolLib: poolLib.address
}
}
);
const poolFactory = await PoolFactory.deploy(
serviceConfiguration.address,
withdrawControllerFactory.address,
poolControllerFactory.address,
poolAccessControlFactory.address
);
await poolFactory.deployed();
console.log(`PermissionedPoolFactory deployed to ${poolFactory.address}`);

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

// We recommend this pattern to be able to use async/await everywhere
Expand Down
Loading