Skip to content

Commit

Permalink
Respond to review comments II
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Aug 11, 2021
1 parent 693818c commit a76b8b8
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 53 deletions.
10 changes: 8 additions & 2 deletions contracts/colony/Colony.sol
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ contract Colony is ColonyStorage, PatriciaTreeProofs, MultiChain {
}

function installExtension(bytes32 _extensionId, uint256 _version)
public stoppable auth returns (address)
public stoppable auth
{
return IColonyNetwork(colonyNetworkAddress).installExtension(_extensionId, _version);
IColonyNetwork(colonyNetworkAddress).installExtension(_extensionId, _version);
}

function upgradeExtension(address _extension, uint256 _newVersion)
Expand All @@ -388,6 +388,12 @@ contract Colony is ColonyStorage, PatriciaTreeProofs, MultiChain {
IColonyNetwork(colonyNetworkAddress).uninstallExtension(_extension);
}

function migrateToMultiExtension(bytes32 _extensionId)
public stoppable auth
{
IColonyNetwork(colonyNetworkAddress).migrateToMultiExtension(_extensionId);
}

function addDomain(uint256 _permissionDomainId, uint256 _childSkillIndex, uint256 _parentDomainId) public
stoppable
authDomain(_permissionDomainId, _childSkillIndex, _parentDomainId)
Expand Down
1 change: 1 addition & 0 deletions contracts/colony/ColonyAuthority.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ contract ColonyAuthority is CommonAuthority {
addRoleCapability(ROOT_ROLE, "upgradeExtension(address,uint256)");
addRoleCapability(ROOT_ROLE, "deprecateExtension(address,bool)");
addRoleCapability(ROOT_ROLE, "uninstallExtension(address)");
addRoleCapability(ROOT_ROLE, "migrateToMultiExtension(bytes32)");
addRoleCapability(ARBITRATION_ROLE, "setExpenditureMetadata(uint256,uint256,uint256,string)");
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/colony/ColonyStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ contract ColonyStorage is CommonStorage, ColonyDataTypes, ColonyNetworkDataTypes
// Ensure addr is an extension installed in the colony, must check old & new formats
try ColonyExtension(addr).identifier() returns (bytes32 extensionId) {
return (
IColonyNetwork(colonyNetworkAddress).getExtensionMultiInstallation(addr) == address(this) ||
IColonyNetwork(colonyNetworkAddress).getExtensionColony(addr) == address(this) ||
IColonyNetwork(colonyNetworkAddress).getExtensionInstallation(extensionId, address(this)) == addr
);
} catch {
Expand Down
7 changes: 5 additions & 2 deletions contracts/colony/IColony.sol
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ interface IColony is ColonyDataTypes, IRecovery {
/// @notice Install an extension to the colony. Secured function to authorised members.
/// @param extensionId keccak256 hash of the extension name, used as an indentifier
/// @param version The new extension version to install
/// @return extension The address of the extension installation
function installExtension(bytes32 extensionId, uint256 version) external returns (address extension);
function installExtension(bytes32 extensionId, uint256 version) external;

/// @notice Upgrade an extension in a colony. Secured function to authorised members.
/// @param extension The address of the extension installation
Expand All @@ -282,6 +281,10 @@ interface IColony is ColonyDataTypes, IRecovery {
/// @param extension The address of the extension installation
function uninstallExtension(address extension) external;

/// @notice Migrate extension bookkeeping to multiExtension. Secured function to authorised members.
/// @param extensionId keccak256 hash of the extension name, used as an indentifier
function migrateToMultiExtension(bytes32 extensionId) external;

/// @notice Add a colony domain, and its respective local skill under skill with id `_parentSkillId`.
/// New funding pot is created and associated with the domain here.
/// @param _permissionDomainId The domainId in which I have the permission to take this action
Expand Down
8 changes: 7 additions & 1 deletion contracts/colonyNetwork/ColonyNetworkDataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ interface ColonyNetworkDataTypes {
/// @param version The version of the extension
event ExtensionAddedToNetwork(bytes32 indexed extensionId, uint256 version);

/// @notice Event logged when an extension is installed in a colony
/// @notice Event logged when an extension is installed in a colony (for v7 and below)
/// @param extensionId The identifier for the extension
/// @param colony The address of the colony
/// @param version The version of the extension
event ExtensionInstalled(bytes32 indexed extensionId, address indexed colony, uint256 version);

/// @notice Event logged when an extension is installed in a colony (for v8 and above)
/// @param extensionId The identifier for the extension
/// @param extension Address of the extension installation
/// @param colony The address of the colony
Expand Down
16 changes: 10 additions & 6 deletions contracts/colonyNetwork/ColonyNetworkExtensions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ contract ColonyNetworkExtensions is ColonyNetworkStorage {
if (IColony(msg.sender).version() <= 7) {
require(installations[_extensionId][msg.sender] == address(0x0), "colony-network-extension-already-installed");
installations[_extensionId][msg.sender] = address(extension);

emit ExtensionInstalled(_extensionId, address(extension), _version);
} else {
multiInstallations[address(extension)] = msg.sender;

emit ExtensionInstalled(_extensionId, address(extension), msg.sender, _version);
}

extension.setResolver(resolvers[_extensionId][_version]);
ColonyExtension(address(extension)).install(msg.sender);

emit ExtensionInstalled(_extensionId, address(extension), msg.sender, _version);

return address(extension);
}
Expand Down Expand Up @@ -160,15 +163,16 @@ contract ColonyNetworkExtensions is ColonyNetworkStorage {
emit ExtensionUninstalled(_extension, msg.sender);
}

function migrateToMultiExtension(bytes32 _extensionId, address _colony)
function migrateToMultiExtension(bytes32 _extensionId)
public
stoppable
calledByColony
{
require(installations[_extensionId][_colony] != address(0x0), "colony-network-extension-not-installed");
require(installations[_extensionId][msg.sender] != address(0x0), "colony-network-extension-not-installed");

multiInstallations[installations[_extensionId][_colony]] = payable(_colony);
multiInstallations[installations[_extensionId][msg.sender]] = payable(msg.sender);

delete installations[_extensionId][_colony];
delete installations[_extensionId][msg.sender];
}

// Public view functions
Expand All @@ -181,7 +185,7 @@ contract ColonyNetworkExtensions is ColonyNetworkStorage {
return resolvers[_extensionId][_version];
}

function getExtensionMultiInstallation(address _extension)
function getExtensionColony(address _extension)
public
view
returns (address)
Expand Down
10 changes: 4 additions & 6 deletions contracts/colonyNetwork/IColonyNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ interface IColonyNetwork is ColonyNetworkDataTypes, IRecovery {
/// @notice Install an extension in a colony. Can only be called by a Colony.
/// @param extensionId keccak256 hash of the extension name, used as an indentifier
/// @param version Version of the extension to install
/// @return extension The address of the extension installation
function installExtension(bytes32 extensionId, uint256 version) external returns (address extension);
function installExtension(bytes32 extensionId, uint256 version) external;

/// @dev DEPRECATED
/// @notice Upgrade an extension in a colony. Can only be called by a Colony.
Expand Down Expand Up @@ -350,10 +349,9 @@ interface IColonyNetwork is ColonyNetworkDataTypes, IRecovery {
/// @param extension Address of the extension installation
function uninstallExtension(address extension) external;

/// @notice Migrate extension bookkeeping to multiExtension
/// @notice Migrate extension bookkeeping to multiExtension. Can only be called by a Colony.
/// @param extensionId keccak256 hash of the extension name, used as an indentifier
/// @param colony Address of the colony the extension is installed in
function migrateToMultiExtension(bytes32 extensionId, address colony) external;
function migrateToMultiExtension(bytes32 extensionId) external;

/// @notice Get an extension's resolver.
/// @param extensionId keccak256 hash of the extension name, used as an indentifier
Expand All @@ -370,7 +368,7 @@ interface IColonyNetwork is ColonyNetworkDataTypes, IRecovery {
/// @notice Get an extension's installed colony.
/// @param extension Address of the extension installation
/// @return colony Address of the colony the extension is installed in
function getExtensionMultiInstallation(address extension) external view returns (address colony);
function getExtensionColony(address extension) external view returns (address colony);

/// @notice Return 1 / the fee to pay to the network. e.g. if the fee is 1% (or 0.01), return 100.
/// @return _feeInverse The inverse of the network fee
Expand Down
17 changes: 12 additions & 5 deletions docs/_Interface_IColony.md
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,6 @@ Install an extension to the colony. Secured function to authorised members.
|extensionId|bytes32|keccak256 hash of the extension name, used as an indentifier
|version|uint256|The new extension version to install

**Return Parameters**

|Name|Type|Description|
|---|---|---|
|extension|address|The address of the extension installation

### `lockExpenditure`

Expand Down Expand Up @@ -1160,6 +1155,18 @@ Make a new task in the colony. Secured function to authorised members.
|_dueDate|uint256|The due date of the task, can set to `0` for no-op


### `migrateToMultiExtension`

Migrate extension bookkeeping to multiExtension. Secured function to authorised members.


**Parameters**

|Name|Type|Description|
|---|---|---|
|extensionId|bytes32|keccak256 hash of the extension name, used as an indentifier


### `mintTokens`

Mint `_wad` amount of colony tokens. Secured function to authorised members.
Expand Down
26 changes: 10 additions & 16 deletions docs/_Interface_IColonyNetwork.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,40 +347,40 @@ Returns the address of the ENSRegistrar for the Network.
|---|---|---|
|address|address|The address the ENSRegistrar resolves to

### `getExtensionInstallation`
### `getExtensionColony`

Get an extension's installation.
Get an extension's installed colony.


**Parameters**

|Name|Type|Description|
|---|---|---|
|extensionId|bytes32|keccak256 hash of the extension name, used as an indentifier
|colony|address|Address of the colony the extension is installed in
|extension|address|Address of the extension installation

**Return Parameters**

|Name|Type|Description|
|---|---|---|
|installation|address|The address of the installed extension
|colony|address|Address of the colony the extension is installed in

### `getExtensionMultiInstallation`
### `getExtensionInstallation`

Get an extension's installed colony.
Get an extension's installation.


**Parameters**

|Name|Type|Description|
|---|---|---|
|extension|address|Address of the extension installation
|extensionId|bytes32|keccak256 hash of the extension name, used as an indentifier
|colony|address|Address of the colony the extension is installed in

**Return Parameters**

|Name|Type|Description|
|---|---|---|
|colony|address|Address of the colony the extension is installed in
|installation|address|The address of the installed extension

### `getExtensionResolver`

Expand Down Expand Up @@ -693,11 +693,6 @@ Install an extension in a colony. Can only be called by a Colony.
|extensionId|bytes32|keccak256 hash of the extension name, used as an indentifier
|version|uint256|Version of the extension to install

**Return Parameters**

|Name|Type|Description|
|---|---|---|
|extension|address|The address of the extension installation

### `isColony`

Expand Down Expand Up @@ -735,15 +730,14 @@ Reverse lookup a username from an address.

### `migrateToMultiExtension`

Migrate extension bookkeeping to multiExtension
Migrate extension bookkeeping to multiExtension. Can only be called by a Colony.


**Parameters**

|Name|Type|Description|
|---|---|---|
|extensionId|bytes32|keccak256 hash of the extension name, used as an indentifier
|colony|address|Address of the colony the extension is installed in


### `punishStakers`
Expand Down
26 changes: 13 additions & 13 deletions test/contracts-network/colony-network-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,21 @@ contract("Colony Network Extensions", (accounts) => {

let colonyAddress;

colonyAddress = await colonyNetwork.getExtensionMultiInstallation(extension.address);
colonyAddress = await colonyNetwork.getExtensionColony(extension.address);
expect(colonyAddress).to.equal(ethers.constants.AddressZero);

// Set up `installations` mapping in the old style
const slot = soliditySha3(`0x000000000000000000000000${colony.address.slice(2)}`, soliditySha3(TEST_EXTENSION, 39));
const value = `0x000000000000000000000000${extension.address.slice(2)}`;
const slot = soliditySha3(ethers.utils.hexZeroPad(colony.address, 32), soliditySha3(TEST_EXTENSION, 39));
const value = ethers.utils.hexZeroPad(extension.address, 32);
await editableColonyNetwork.setStorageSlot(slot, value);

let extensionAddress;
extensionAddress = await colonyNetwork.getExtensionInstallation(TEST_EXTENSION, colony.address);
expect(extensionAddress).to.not.equal(ethers.constants.AddressZero);

await colonyNetwork.migrateToMultiExtension(TEST_EXTENSION, colony.address);
await colony.migrateToMultiExtension(TEST_EXTENSION);

colonyAddress = await colonyNetwork.getExtensionMultiInstallation(extension.address);
colonyAddress = await colonyNetwork.getExtensionColony(extension.address);
expect(colonyAddress).to.equal(colony.address);

extensionAddress = await colonyNetwork.getExtensionInstallation(TEST_EXTENSION, colony.address);
Expand All @@ -221,8 +221,8 @@ contract("Colony Network Extensions", (accounts) => {
const version7Colony = await Version7.new(colonyNetwork.address);

// Add version7Colony to _isColony mapping
const slot = soliditySha3(`0x000000000000000000000000${version7Colony.address.slice(2)}`, 19);
const value = `0x0000000000000000000000000000000000000000000000000000000000000001`;
const slot = soliditySha3(ethers.utils.hexZeroPad(version7Colony.address, 32), 19);
const value = ethers.utils.zeroPad(1, 32);
await editableColonyNetwork.setStorageSlot(slot, value);

await version7Colony.installExtension(TEST_EXTENSION, 1);
Expand Down Expand Up @@ -297,8 +297,8 @@ contract("Colony Network Extensions", (accounts) => {
const version7Colony = await Version7.new(colonyNetwork.address);

// Add version7Colony to _isColony mapping
const slot = soliditySha3(`0x000000000000000000000000${version7Colony.address.slice(2)}`, 19);
const value = `0x0000000000000000000000000000000000000000000000000000000000000001`;
const slot = soliditySha3(ethers.utils.hexZeroPad(version7Colony.address, 32), 19);
const value = ethers.utils.zeroPad(1, 32);
await editableColonyNetwork.setStorageSlot(slot, value);

await version7Colony.installExtension(TEST_EXTENSION, 1);
Expand Down Expand Up @@ -346,8 +346,8 @@ contract("Colony Network Extensions", (accounts) => {
const version7Colony = await Version7.new(colonyNetwork.address);

// Add version7Colony to _isColony mapping
const slot = soliditySha3(`0x000000000000000000000000${version7Colony.address.slice(2)}`, 19);
const value = `0x0000000000000000000000000000000000000000000000000000000000000001`;
const slot = soliditySha3(ethers.utils.hexZeroPad(version7Colony.address, 32), 19);
const value = ethers.utils.zeroPad(1, 32);
await editableColonyNetwork.setStorageSlot(slot, value);

await version7Colony.installExtension(TEST_EXTENSION, 1);
Expand Down Expand Up @@ -397,8 +397,8 @@ contract("Colony Network Extensions", (accounts) => {
const version7Colony = await Version7.new(colonyNetwork.address);

// Add version7Colony to _isColony mapping
const slot = soliditySha3(`0x000000000000000000000000${version7Colony.address.slice(2)}`, 19);
const value = `0x0000000000000000000000000000000000000000000000000000000000000001`;
const slot = soliditySha3(ethers.utils.hexZeroPad(version7Colony.address, 32), 19);
const value = ethers.utils.zeroPad(1, 32);
await editableColonyNetwork.setStorageSlot(slot, value);

await version7Colony.installExtension(TEST_EXTENSION, 1);
Expand Down
2 changes: 1 addition & 1 deletion test/extensions/voting-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ contract("Voting Reputation", (accounts) => {
expect(tx.logs[1].args.executed).to.be.true;

const extensionAddress = getExtensionAddressFromTx(tx);
const colonyAddress = await colonyNetwork.getExtensionMultiInstallation(extensionAddress);
const colonyAddress = await colonyNetwork.getExtensionColony(extensionAddress);
expect(colonyAddress).to.equal(colony.address);
});

Expand Down

0 comments on commit a76b8b8

Please sign in to comment.