-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [x] Override deploy steps for poll factory and maci - [x] Integration maci protocol deploy tasks
- Loading branch information
Showing
10 changed files
with
884 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
/** | ||
* The same as individual imports but doesn't require to add new import line every time | ||
*/ | ||
["maci"].forEach((folder) => { | ||
const tasksPath = path.resolve(__dirname, folder); | ||
|
||
if (fs.existsSync(tasksPath)) { | ||
fs.readdirSync(tasksPath) | ||
.filter( | ||
(p) => | ||
(p.endsWith(".ts") && !p.endsWith("index.ts") && !p.endsWith("d.ts")) || | ||
(p.endsWith(".js") && !p.endsWith("index.js")), | ||
) | ||
.forEach((task) => { | ||
import(`${tasksPath}/${task}`); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { ContractStorage, Deployment, EContracts, type IDeployParams } from "maci-contracts"; | ||
|
||
import { EDeploySteps } from "../../helpers/constants"; | ||
|
||
const deployment = Deployment.getInstance(); | ||
const storage = ContractStorage.getInstance(); | ||
|
||
/** | ||
* Deploy step registration and task itself | ||
*/ | ||
deployment.deployTask(EDeploySteps.PollFactory, "Deploy poll factory").then((task) => | ||
task.setAction(async ({ incremental }: IDeployParams, hre) => { | ||
deployment.setHre(hre); | ||
const deployer = await deployment.getDeployer(); | ||
|
||
const pollFactoryContractAddress = storage.getAddress(EContracts.PollFactory, hre.network.name); | ||
|
||
if (incremental && pollFactoryContractAddress) { | ||
return; | ||
} | ||
|
||
const poseidonT3ContractAddress = storage.mustGetAddress(EContracts.PoseidonT3, hre.network.name); | ||
const poseidonT4ContractAddress = storage.mustGetAddress(EContracts.PoseidonT4, hre.network.name); | ||
const poseidonT5ContractAddress = storage.mustGetAddress(EContracts.PoseidonT5, hre.network.name); | ||
const poseidonT6ContractAddress = storage.mustGetAddress(EContracts.PoseidonT6, hre.network.name); | ||
|
||
const linkedPollFactoryContract = await hre.ethers.getContractFactory( | ||
"contracts/maci/PollFactory.sol:PollFactory", | ||
{ | ||
signer: deployer, | ||
libraries: { | ||
PoseidonT3: poseidonT3ContractAddress, | ||
PoseidonT4: poseidonT4ContractAddress, | ||
PoseidonT5: poseidonT5ContractAddress, | ||
PoseidonT6: poseidonT6ContractAddress, | ||
}, | ||
}, | ||
); | ||
|
||
const pollFactoryContract = await deployment.deployContractWithLinkedLibraries({ | ||
contractFactory: linkedPollFactoryContract, | ||
}); | ||
|
||
await storage.register({ | ||
id: EContracts.PollFactory, | ||
contract: pollFactoryContract, | ||
args: [], | ||
network: hre.network.name, | ||
}); | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { | ||
ContractStorage, | ||
Deployment, | ||
EContracts, | ||
genEmptyBallotRoots, | ||
type IDeployParams, | ||
type GitcoinPassportGatekeeper, | ||
type EASGatekeeper, | ||
type ZupassGatekeeper, | ||
type SemaphoreGatekeeper, | ||
type HatsGatekeeperBase, | ||
} from "maci-contracts"; | ||
|
||
import { MACI } from "../../../typechain-types"; | ||
import { EDeploySteps } from "../../helpers/constants"; | ||
|
||
const deployment = Deployment.getInstance(); | ||
const storage = ContractStorage.getInstance(); | ||
|
||
const DEFAULT_STATE_TREE_DEPTH = 10; | ||
|
||
/** | ||
* Deploy step registration and task itself | ||
*/ | ||
deployment.deployTask(EDeploySteps.Maci, "Deploy MACI contract").then((task) => | ||
task.setAction(async ({ incremental }: IDeployParams, hre) => { | ||
deployment.setHre(hre); | ||
const deployer = await deployment.getDeployer(); | ||
|
||
const maciContractAddress = storage.getAddress(EContracts.MACI, hre.network.name); | ||
|
||
if (incremental && maciContractAddress) { | ||
return; | ||
} | ||
|
||
const poseidonT3ContractAddress = storage.mustGetAddress(EContracts.PoseidonT3, hre.network.name); | ||
const poseidonT4ContractAddress = storage.mustGetAddress(EContracts.PoseidonT4, hre.network.name); | ||
const poseidonT5ContractAddress = storage.mustGetAddress(EContracts.PoseidonT5, hre.network.name); | ||
const poseidonT6ContractAddress = storage.mustGetAddress(EContracts.PoseidonT6, hre.network.name); | ||
|
||
const maciContractFactory = await hre.ethers.getContractFactory("contracts/maci/MACI.sol:MACI", { | ||
signer: deployer, | ||
libraries: { | ||
PoseidonT3: poseidonT3ContractAddress, | ||
PoseidonT4: poseidonT4ContractAddress, | ||
PoseidonT5: poseidonT5ContractAddress, | ||
PoseidonT6: poseidonT6ContractAddress, | ||
}, | ||
}); | ||
|
||
const constantInitialVoiceCreditProxyContractAddress = storage.mustGetAddress( | ||
EContracts.ConstantInitialVoiceCreditProxy, | ||
hre.network.name, | ||
); | ||
const gatekeeper = | ||
deployment.getDeployConfigField<EContracts | null>(EContracts.MACI, "gatekeeper") || | ||
EContracts.FreeForAllGatekeeper; | ||
const gatekeeperContractAddress = storage.mustGetAddress(gatekeeper, hre.network.name); | ||
const pollFactoryContractAddress = storage.mustGetAddress(EContracts.PollFactory, hre.network.name); | ||
const messageProcessorFactoryContractAddress = storage.mustGetAddress( | ||
EContracts.MessageProcessorFactory, | ||
hre.network.name, | ||
); | ||
const tallyFactoryContractAddress = storage.mustGetAddress(EContracts.TallyFactory, hre.network.name); | ||
|
||
const stateTreeDepth = | ||
deployment.getDeployConfigField<number | null>(EContracts.MACI, "stateTreeDepth") ?? DEFAULT_STATE_TREE_DEPTH; | ||
|
||
const emptyBallotRoots = genEmptyBallotRoots(stateTreeDepth); | ||
|
||
const maciContract = await deployment.deployContractWithLinkedLibraries<MACI>( | ||
{ contractFactory: maciContractFactory }, | ||
pollFactoryContractAddress, | ||
messageProcessorFactoryContractAddress, | ||
tallyFactoryContractAddress, | ||
gatekeeperContractAddress, | ||
constantInitialVoiceCreditProxyContractAddress, | ||
stateTreeDepth, | ||
emptyBallotRoots, | ||
); | ||
|
||
if (gatekeeper === EContracts.EASGatekeeper) { | ||
const gatekeeperContract = await deployment.getContract<EASGatekeeper>({ | ||
name: EContracts.EASGatekeeper, | ||
address: gatekeeperContractAddress, | ||
}); | ||
const maciInstanceAddress = await maciContract.getAddress(); | ||
|
||
await gatekeeperContract.setMaciInstance(maciInstanceAddress).then((tx) => tx.wait()); | ||
} else if (gatekeeper === EContracts.GitcoinPassportGatekeeper) { | ||
const gatekeeperContract = await deployment.getContract<GitcoinPassportGatekeeper>({ | ||
name: EContracts.GitcoinPassportGatekeeper, | ||
address: gatekeeperContractAddress, | ||
}); | ||
const maciInstanceAddress = await maciContract.getAddress(); | ||
|
||
await gatekeeperContract.setMaciInstance(maciInstanceAddress).then((tx) => tx.wait()); | ||
} else if (gatekeeper === EContracts.ZupassGatekeeper) { | ||
const gatekeeperContract = await deployment.getContract<ZupassGatekeeper>({ | ||
name: EContracts.ZupassGatekeeper, | ||
address: gatekeeperContractAddress, | ||
}); | ||
const maciInstanceAddress = await maciContract.getAddress(); | ||
await gatekeeperContract.setMaciInstance(maciInstanceAddress).then((tx) => tx.wait()); | ||
} else if (gatekeeper === EContracts.SemaphoreGatekeeper) { | ||
const gatekeeperContract = await deployment.getContract<SemaphoreGatekeeper>({ | ||
name: EContracts.SemaphoreGatekeeper, | ||
address: gatekeeperContractAddress, | ||
}); | ||
|
||
const maciInstanceAddress = await maciContract.getAddress(); | ||
await gatekeeperContract.setMaciInstance(maciInstanceAddress).then((tx) => tx.wait()); | ||
} else if (gatekeeper === EContracts.HatsGatekeeper) { | ||
const gatekeeperContract = await deployment.getContract<HatsGatekeeperBase>({ | ||
name: EContracts.HatsGatekeeper, | ||
address: gatekeeperContractAddress, | ||
}); | ||
|
||
const maciInstanceAddress = await maciContract.getAddress(); | ||
await gatekeeperContract.setMaciInstance(maciInstanceAddress).then((tx) => tx.wait()); | ||
} | ||
|
||
await storage.register({ | ||
id: EContracts.MACI, | ||
contract: maciContract, | ||
args: [ | ||
pollFactoryContractAddress, | ||
messageProcessorFactoryContractAddress, | ||
tallyFactoryContractAddress, | ||
gatekeeperContractAddress, | ||
constantInitialVoiceCreditProxyContractAddress, | ||
stateTreeDepth, | ||
emptyBallotRoots.map((root) => root.toString()), | ||
], | ||
network: hre.network.name, | ||
}); | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.