Skip to content

Commit

Permalink
Merge pull request #35 from brossetti1/br-config-updates
Browse files Browse the repository at this point in the history
Br config updates
  • Loading branch information
brossetti1 authored Feb 3, 2022
2 parents 356c24c + 34c48cf commit f49a59d
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DEV_PRIVATE_KEY=""
INFURA_KEY=""
ZKSYNC_NETWORK=""
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ deployments/
typechain/

# zkSync
contracts/tmp
contracts/tmp

# dotenv
.env
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Live at [http://cadastre.geoweb.eth.link/](http://cadastre.geoweb.eth.link/) or [ipns://cadastre.geoweb.eth](ipns://cadastre.geoweb.eth)

## Setup

Make sure to make a `.env` file in the root of your project based off the `.env.example` file.

## Tasks

### Deploy
Expand Down
22 changes: 11 additions & 11 deletions deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export default async function (hre: HardhatRuntimeEnvironment) {

// Accountant default config
await hre.run("config:accountant", {
contract: accountant,
contractAddress: accountant.address,
annualFeeRate: 0.1,
validator: collector.address,
});

// ETHExpirationCollector default config
await hre.run("config:collector", {
contract: collector,
contractAddress: collector.address,
minContributionRate: hre.ethers.utils
.parseEther("0.01")
.div(60 * 60 * 24 * 365)
Expand All @@ -42,7 +42,7 @@ export default async function (hre: HardhatRuntimeEnvironment) {

// ETHPurchaser default config
await hre.run("config:purchaser", {
contract: purchaser,
contractAddress: purchaser.address,
dutchAuctionLength: 60 * 60 * 24 * 7, // 7 days
licenseAddress: license.address,
accountantAddress: accountant.address,
Expand All @@ -51,7 +51,7 @@ export default async function (hre: HardhatRuntimeEnvironment) {

// SimpleETHClaimer default config
await hre.run("config:claimer", {
contract: claimer,
contractAddress: claimer.address,
minClaimExpiration: 60 * 60 * 24 * 7, // 7 days
licenseAddress: license.address,
parcelAddress: parcel.address,
Expand All @@ -63,12 +63,12 @@ export default async function (hre: HardhatRuntimeEnvironment) {
console.log("\nSetting roles...");
// Set roles
await hre.run("roles:set-default", {
license: license,
parcel: parcel,
accountant: accountant,
purchaser: purchaser,
collector: collector,
claimer: claimer,
licenseAddress: license.address,
parcelAddress: parcel.address,
accountantAddress: accountant.address,
purchaserAddress: purchaser.address,
collectorAddress: collector.address,
claimerAddress: claimer.address,
});
console.log("Default roles set.");
}
}
93 changes: 47 additions & 46 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
* @type import('hardhat/config').HardhatUserConfig
*/

require("@matterlabs/hardhat-zksync-deploy");
require("@matterlabs/hardhat-zksync-solc");
import * as dotenv from "dotenv";

if (process.env.NODE_ENV !== 'production') {
dotenv.config()
}

// require("@matterlabs/hardhat-zksync-deploy");
// require("@matterlabs/hardhat-zksync-solc");
import { task, types } from "hardhat/config";
import "@nomiclabs/hardhat-waffle";
import { ethers } from "ethers";
Expand All @@ -23,12 +29,12 @@ task(
"Deploy the set of contracts with default configuration"
).setAction(async (args, hre) => {
console.log("Deploying all contracts...");
const parcel = await hre.run("deploy:parcel");
const accountant = await hre.run("deploy:accountant");
const license = await hre.run("deploy:license");
const purchaser = await hre.run("deploy:purchaser");
const collector = await hre.run("deploy:collector");
const claimer = await hre.run("deploy:claimer");
const parcelAddress = await hre.run("deploy:parcel");
const accountantAddress = await hre.run("deploy:accountant");
const licenseAddress = await hre.run("deploy:license");
const purchaserAddress = await hre.run("deploy:purchaser");
const collectorAddress = await hre.run("deploy:collector");
const claimerAddress = await hre.run("deploy:claimer");
console.log("Contracts deployed.");

console.log("\nSetting default configuration...");
Expand All @@ -37,54 +43,54 @@ task(

// Accountant default config
await hre.run("config:accountant", {
contract: accountant,
contractAddress: accountantAddress,
annualFeeRate: 0.1,
validator: collector,
validator: collectorAddress,
});

// ETHExpirationCollector default config
await hre.run("config:collector", {
contract: collector,
licenseAddress,
accountantAddress,
contractAddress: collectorAddress,
minContributionRate: hre.ethers.utils
.parseEther("0.01")
.div(60 * 60 * 24 * 365)
.toString(),
minExpiration: 60 * 60 * 24 * 7, // 7 days
maxExpiration: 60 * 60 * 24 * 730, // 730 days
license: license,
receiver: accounts[0].address,
accountant: accountant,
});

// ETHPurchaser default config
await hre.run("config:purchaser", {
contract: purchaser,
licenseAddress,
accountantAddress,
collectorAddress,
contractAddress: purchaserAddress,
dutchAuctionLength: 60 * 60 * 24 * 7, // 7 days
license: license,
accountant: accountant,
collector: collector,
});

// SimpleETHClaimer default config
await hre.run("config:claimer", {
contract: claimer,
contractAddress: claimerAddress,
licenseAddress,
parcelAddress,
collectorAddress,
minClaimExpiration: 60 * 60 * 24 * 7, // 7 days
license: license,
parcel: parcel,
collector: collector,
});

console.log("Default configuration set.");

console.log("\nSetting roles...");
// Set roles
await hre.run("roles:set-default", {
license: license,
parcel: parcel,
accountant: accountant,
purchaser: purchaser,
collector: collector,
claimer: claimer,
licenseAddress,
accountantAddress,
collectorAddress,
parcelAddress,
purchaserAddress,
claimerAddress,
});
console.log("Default roles set.");
});
Expand All @@ -101,65 +107,60 @@ task("deploy:contracts-only", "Deploy the set of bare contracts").setAction(
);

task("roles:set-default", "Set default roles on all deployed contracts")
.addOptionalParam("license", "ERC721 License used to find owners", undefined, types.json)
.addOptionalParam("accountant", "Accountant", undefined, types.json)
.addOptionalParam("collector", "ETHExpirationCollector", undefined, types.json)
.addOptionalParam("parcel", "GeoWebParcel", undefined, types.json)
.addOptionalParam("purchaser", "ETHPurchaser", undefined, types.json)
.addOptionalParam("claimer", "SimpleETHClaimer", undefined, types.json)
.addOptionalParam("licenseAddress", "Address of ERC721 License used to find owners", undefined, types.string)
.addOptionalParam("accountantAddress", "Address of Accountant", undefined, types.string)
.addOptionalParam("collectorAddress", "Address of ETHExpirationCollector", undefined, types.string)
.addOptionalParam("parcelAddress", "Address of GeoWebParcel", undefined, types.string)
.addOptionalParam("purchaserAddress", "Address of ETHPurchaser", undefined, types.string)
.addOptionalParam("claimerAddress", "Address of SimpleETHClaimer", undefined, types.string)
.setAction(
async ({ license, accountant, collector, parcel, purchaser, claimer, licenseAddress, accountantAddress, collectorAddress, parcelAddress, purchaserAddress, claimerAddress }: { license?: ethers.Contract, accountant?: ethers.Contract, collector?: ethers.Contract, parcel?: ethers.Contract, purchaser?: ethers.Contract, claimer?: ethers.Contract, licenseAddress?: string, accountantAddress?: string, collectorAddress?: string, parcelAddress?: string, purchaserAddress?: string, claimerAddress?: string }, hre) => {
const licenseContract = licenseAddress ? await hre.ethers.getContractAt(
async ({ licenseAddress, accountantAddress, collectorAddress, parcelAddress, purchaserAddress, claimerAddress }: { licenseAddress: string, accountantAddress: string, collectorAddress: string, parcelAddress: string, purchaserAddress: string, claimerAddress: string }, hre) => {
const licenseContract = await hre.ethers.getContractAt(
"ERC721License",
licenseAddress
): license!;
const collectorContract = collectorAddress ? await hre.ethers.getContractAt(
);
const collectorContract = await hre.ethers.getContractAt(
"ETHExpirationCollector",
collectorAddress
): collector!;
const parcelContract = parcelAddress ? await hre.ethers.getContractAt("GeoWebParcel", parcelAddress) : parcel!;
);

const parcelContract = await hre.ethers.getContractAt("GeoWebParcel", parcelAddress);

await hre.run("roles:accountant", {
accountant: accountant,
collectorAddress: collectorAddress ?? collector!.address,
accountantAddress,
collectorAddress,
});

// ERC721License roles
const res2 = await licenseContract.grantRole(
await licenseContract.MINT_ROLE(),
claimerAddress ?? claimer!.address
claimerAddress
);
await res2.wait();

const res3 = await licenseContract.grantRole(
await licenseContract.OPERATOR_ROLE(),
purchaserAddress ?? purchaser!.address
purchaserAddress
);
await res3.wait();

// ETHExpirationCollector roles
const res4 = await collectorContract.grantRole(
await collectorContract.MODIFY_CONTRIBUTION_ROLE(),
claimerAddress ?? claimer!.address
claimerAddress
);
await res4.wait();

const res5 = await collectorContract.grantRole(
await collectorContract.MODIFY_CONTRIBUTION_ROLE(),
purchaserAddress ?? purchaser!.address
purchaserAddress
);
await res5.wait();

// GeoWebParcel roles
const res6 = await parcelContract.grantRole(
await parcelContract.BUILD_ROLE(),
claimerAddress ?? claimer!.address
claimerAddress
);
await res6.wait();
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@openzeppelin/hardhat-upgrades": "^1.9.0",
"@openzeppelin/truffle-upgrades": "^1.3.1",
"@types/node": "^17.0.8",
"dotenv": "^14.3.2",
"chai": "^4.3.4",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.4.2",
Expand Down
13 changes: 6 additions & 7 deletions tasks/Accountant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ task("deploy-zksync:accountant", "Deploy the Accountant").setAction(async ({depl
});

task("config:accountant")
.addOptionalParam("contract", "Accountant contract", undefined, types.json)
.addOptionalParam("contractAddress", "Accountant contract address", undefined, types.string)
.addOptionalParam(
"annualFeeRate",
Expand All @@ -40,13 +39,13 @@ task("config:accountant")
"validator",
"Where to find if a license's account is still valid"
)
.setAction(async ({ contract, contractAddress, annualFeeRate, validator }: {contract?: ethers.Contract, contractAddress?: string, annualFeeRate?: number, validator?: string}, hre) => {
.setAction(async ({ contractAddress, annualFeeRate, validator }: { contractAddress: string, annualFeeRate?: number, validator?: string}, hre) => {
if (!annualFeeRate && !validator) {
console.log("Nothing to configure. See options");
return;
}

const accountant = contractAddress ? await hre.ethers.getContractAt("Accountant", contractAddress) : contract!;
const accountant = await hre.ethers.getContractAt("Accountant", contractAddress);

if (annualFeeRate) {
const { numerator, denominator } = perYearToPerSecondRate(annualFeeRate);
Expand All @@ -63,20 +62,20 @@ task("config:accountant")
});

task("roles:accountant", "Set default roles for Accountant")
.addOptionalParam("accountant", "Accountant contract", undefined, types.json)
.addOptionalParam("accountantAddress", "Address of Accountant", undefined, types.string)
.addParam("collectorAddress", "Address of ETHExpirationCollector")
.setAction(async ({ accountant, accountantAddress, collectorAddress }: {accountant?: ethers.Contract, accountantAddress?: string, collectorAddress: string}, hre) => {
const accountantContract = accountantAddress ? await hre.ethers.getContractAt(
.setAction(async ({ accountantAddress, collectorAddress }: { accountantAddress: string, collectorAddress: string}, hre) => {
const accountantContract = await hre.ethers.getContractAt(
"Accountant",
accountantAddress
) : accountant!;
)

// Accountant roles
const res1 = await accountantContract.grantRole(
await accountantContract.MODIFY_CONTRIBUTION_ROLE(),
collectorAddress
);

await res1.wait();

console.log(
Expand Down
9 changes: 3 additions & 6 deletions tasks/ETHExpirationCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ task("deploy-zksync:collector", "Deploy the ETHExpirationCollector").setAction(


task("config:collector")
.addOptionalParam("contract", "Deployed ETHExpirationCollector contract", undefined, types.json)
.addOptionalParam("contractAddress", "Address of deployed ETHExpirationCollector contract", undefined, types.string)
.addOptionalParam(
"minContributionRate",
Expand All @@ -51,7 +50,6 @@ task("config:collector")
.addOptionalParam("receiver", "Address of receiver of contributions")
.setAction(
async ({
contract,
contractAddress,
minContributionRate,
minExpiration,
Expand All @@ -60,8 +58,7 @@ task("config:collector")
receiver,
accountantAddress,
}: {
contract?: ethers.Contract,
contractAddress?: string,
contractAddress: string,
minContributionRate?: string,
minExpiration?: number,
maxExpiration?: number,
Expand All @@ -81,10 +78,10 @@ task("config:collector")
return;
}

const collector = contractAddress ? await hre.ethers.getContractAt(
const collector = await hre.ethers.getContractAt(
"ETHExpirationCollector",
contractAddress
): contract!;
)

if (minContributionRate) {
const res = await collector.setMinContributionRate(minContributionRate);
Expand Down
5 changes: 2 additions & 3 deletions tasks/ETHPurchaser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ task("deploy-zksync:purchaser", "Deploy the ETHPurchaser").setAction(
);

task("config:purchaser")
.addOptionalParam("contract", "Deployed ETHPurchaser contract", undefined, types.json)
.addOptionalParam("contractAddress", "Address of deployed ETHPurchaser contract", undefined, types.string)
.addOptionalParam(
"dutchAuctionLength",
Expand All @@ -38,15 +37,15 @@ task("config:purchaser")
.addOptionalParam("collectorAddress", "Address of ETHExpirationCollector")
.setAction(
async (
{ contract, contractAddress, dutchAuctionLength, licenseAddress, accountantAddress, collectorAddress }: { contract?: ethers.Contract, contractAddress?: string, dutchAuctionLength?: number, licenseAddress?: string, accountantAddress?: string, collectorAddress?: string },
{ contractAddress, dutchAuctionLength, licenseAddress, accountantAddress, collectorAddress }: { contractAddress: string, dutchAuctionLength?: number, licenseAddress?: string, accountantAddress?: string, collectorAddress?: string },
hre
) => {
if (!dutchAuctionLength && !licenseAddress && !accountantAddress && !collectorAddress) {
console.log("Nothing to configure. See options");
return;
}

const purchaser = contractAddress ? await hre.ethers.getContractAt("ETHPurchaser", contractAddress) : contract!;
const purchaser = await hre.ethers.getContractAt("ETHPurchaser", contractAddress);

if (dutchAuctionLength) {
const res = await purchaser.setDutchAuctionLengthInSeconds(
Expand Down
Loading

0 comments on commit f49a59d

Please sign in to comment.