Skip to content

Commit

Permalink
fix factory deployment to avoid re-deploying identity contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
adridadou committed Oct 11, 2021
1 parent 1f09ee5 commit b2436a0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 39 deletions.
43 changes: 9 additions & 34 deletions utils/DeploymentUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,31 @@ const deployDao = async (options) => {
? parseInt(options.erc20TokenDecimals) || 0
: 0;

const identityDao = await deployFunction(DaoRegistry);
const identityBank = await deployFunction(BankExtension);
const bankFactory = await deployFunction(BankFactory, [identityBank.address]);
const bankFactory = await deployFunction(BankFactory, [BankExtension]);

const identityERC1271 = await deployFunction(ERC1271Extension);
const erc1271Factory = await deployFunction(ERC1271ExtensionFactory, [
identityERC1271.address,
ERC1271Extension,
]);

const identityNft = await deployFunction(NFTExtension);
const nftFactory = await deployFunction(NFTCollectionFactory, [
identityNft.address,
]);
const nftFactory = await deployFunction(NFTCollectionFactory, [NFTExtension]);

const identityERC20Ext = await deployFunction(ERC20Extension);
const erc20TokenExtFactory = await deployFunction(
ERC20TokenExtensionFactory,
[identityERC20Ext.address]
[ERC20Extension]
);

const identityExecutorExt = await deployFunction(ExecutorExtension);
const executorExtensionFactory = await deployFunction(
ExecutorExtensionFactory,
[identityExecutorExt.address]
[ExecutorExtension]
);

const identityERC1155Ext = await deployFunction(ERC1155TokenExtension);
const erc1155TokenExtFactory = await deployFunction(
ERC1155TokenCollectionFactory,
[identityERC1155Ext.address]
[ERC1155TokenExtension]
);

const { dao, daoFactory } = await cloneDao({
...options,
identityDao,
name: options.daoName || "test-dao",
});

Expand Down Expand Up @@ -144,11 +134,11 @@ const deployDao = async (options) => {
ExecutorExtension
);

const identityVesting = await deployFunction(InternalTokenVestingExtension);
const internalTokenVestingExtensionFactory = await deployFunction(
InternalTokenVestingExtensionFactory,
[identityVesting.address]
[InternalTokenVestingExtension]
);

const internalTokenVestingExtension = await createInternalTokenVestingExtension(
dao,
owner,
Expand Down Expand Up @@ -407,15 +397,6 @@ const prepareAdapters = async ({
};
};

const createIdentityDao = async (options) => {
let { DaoRegistry } = options;

return await DaoRegistry.new({
from: options.owner,
gasPrice: toBN("0"),
});
};

const addDefaultAdapters = async ({ dao, options, daoFactory, nftAddr }) => {
const {
voting,
Expand Down Expand Up @@ -959,19 +940,14 @@ const configureDao = async ({
};

const cloneDao = async ({
identityDao,
owner,
creator,
deployFunction,
DaoRegistry,
DaoFactory,
name,
}) => {
let daoFactory = await deployFunction(
DaoFactory,
[identityDao.address],
owner
);
let daoFactory = await deployFunction(DaoFactory, [DaoRegistry], owner);

await daoFactory.createDao(name, creator ? creator : owner, { from: owner });

Expand Down Expand Up @@ -1277,7 +1253,6 @@ const getNetworkDetails = (name) => {

module.exports = {
deployDao,
createIdentityDao,
cloneDao,
prepareAdapters,
addDefaultAdapters,
Expand Down
22 changes: 19 additions & 3 deletions utils/OZTestUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,29 @@ const {

const { expectRevert } = require("@openzeppelin/test-helpers");
const { expect } = require("chai");
const { ContractType } = require("../deployment/contracts.config");

const deployFunction = async (contractInterface, args, from) => {
if (!contractInterface) throw Error("undefined contract interface");
const { contracts } = require("../deployment/test.config");

const contractConfig = contracts.find(
(c) => c.name === contractInterface.contractName
);

const f = from ? from : accounts[0];
if (args) {
return await contractInterface.new(...args, { from: f });
if (contractConfig.type === ContractType.Factory) {
const identity = await args[0].new({ from: f });
return await contractInterface.new(
...[identity.address].concat(args.slice(1)),
{ from: f }
);
} else {
return await contractInterface.new({ from: f });
if (args) {
return await contractInterface.new(...args, { from: f });
} else {
return await contractInterface.new({ from: f });
}
}
};

Expand All @@ -72,6 +87,7 @@ const getOpenZeppelinContracts = (contracts) => {
.filter((c) => c.enabled)
.reduce((previousValue, contract) => {
previousValue[contract.name] = getContractFromOpenZeppelin(contract.path);
previousValue[contract.name].contractName = contract.name;
return previousValue;
}, {});
};
Expand Down
12 changes: 10 additions & 2 deletions utils/TruffleUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ const deployFunction = (deployer, daoArtifacts, allContracts) => {
);
return await contractInterface.at(address);
}

let deployedContract;
// When the contract is not found in the DaoArtifacts, deploy a new one
const deployedContract = await deploy(contractInterface, args);
if (contractConfig.type === ContractType.Factory) {
const identity = await deploy(args[0]);
deployedContract = await deploy(
contractInterface,
[identity.address].concat(args.slice(1))
);
} else {
deployedContract = await deploy(contractInterface, args);
}

if (
// Add the new contract to DaoArtifacts, should not store Core, Extension & Test contracts
Expand Down

0 comments on commit b2436a0

Please sign in to comment.