Skip to content

Commit

Permalink
Upgrade extension contracts WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed May 15, 2024
1 parent 4c0e7fc commit 6181c43
Show file tree
Hide file tree
Showing 36 changed files with 122 additions and 505 deletions.
4 changes: 3 additions & 1 deletion contracts/colonyNetwork/ColonyNetworkAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ contract DutchAuction is DSMath, MultiChain, BasicMetaTransaction {
assert(clnyToken.balanceOf(address(this)) == 0);
// slither-disable-next-line incorrect-equality
assert(token.balanceOf(address(this)) == 0);
selfdestruct(colonyNetwork);
// Send ether to the metaColony
// slither-disable-next-line arbitrary-send-eth
payable(metaColonyAddress).transfer(address(this).balance);
}
}
16 changes: 5 additions & 11 deletions contracts/extensions/CoinMachine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ERC20 } from "./../../lib/dappsys/erc20.sol";
import { BasicMetaTransaction } from "./../common/BasicMetaTransaction.sol";
import { ColonyExtension } from "./ColonyExtension.sol";
import { Whitelist } from "./Whitelist.sol";
import { IColony, ColonyDataTypes } from "./../colony/IColony.sol";
import { ColonyDataTypes } from "./../colony/IColony.sol";

// ignore-file-swc-108

Expand Down Expand Up @@ -91,7 +91,7 @@ contract CoinMachine is ColonyExtension, BasicMetaTransaction {
_;
}

// Public
// Interface overrides

/// @notice Returns the identifier of the extension
/// @return _identifier The extension's identifier
Expand All @@ -105,14 +105,6 @@ contract CoinMachine is ColonyExtension, BasicMetaTransaction {
return 10;
}

/// @notice Configures the extension
/// @param _colony The colony in which the extension holds permissions
function install(address _colony) public override auth {
require(address(colony) == address(0x0), "extension-already-installed");

colony = IColony(_colony);
}

/// @notice Called when upgrading the extension
function finishUpgrade() public override auth {
token = colony.getToken();
Expand Down Expand Up @@ -143,9 +135,11 @@ contract CoinMachine is ColonyExtension, BasicMetaTransaction {
}
}

selfdestruct(payable(address(colony)));
super.uninstall();
}

// Public

/// @notice Must be called before any sales can be made
/// @param _token The token we are selling. Cannot be ether
/// @param _purchaseToken The token to receive payments in. Use 0x0 for ether
Expand Down
20 changes: 15 additions & 5 deletions contracts/extensions/ColonyExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract contract ColonyExtension is DSAuth, DSMath, PatriciaTreeProofs, Multica

event ExtensionInitialised();

address resolver; // Align storage with EtherRouter
address public resolver; // Align storage with EtherRouter

IColony colony;
bool deprecated;
Expand All @@ -44,17 +44,27 @@ abstract contract ColonyExtension is DSAuth, DSMath, PatriciaTreeProofs, Multica
_;
}

/// @notice Returns the identifier of the extension
/// @return _identifier The extension's identifier
function identifier() public pure virtual returns (bytes32);

function version() public pure virtual returns (uint256);

function install(address _colony) public virtual;
function install(address _colony) public virtual auth {
require(address(colony) == address(0x0), "extension-already-installed");
colony = IColony(_colony);
}

function finishUpgrade() public virtual;
function deprecate(bool _deprecated) public virtual auth {
deprecated = _deprecated;
}

function deprecate(bool _deprecated) public virtual;
function uninstall() public virtual auth {
resolver = address(0x0);
payable(address(colony)).transfer(address(this).balance);
}

function uninstall() public virtual;
function finishUpgrade() public virtual auth {} // solhint-disable-line no-empty-blocks

function getCapabilityRoles(bytes4 _sig) public view virtual returns (bytes32) {
return bytes32(0);
Expand Down
3 changes: 3 additions & 0 deletions contracts/extensions/ColonyExtensionMeta.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { ColonyExtension } from "./ColonyExtension.sol";
abstract contract ColonyExtensionMeta is ColonyExtension, BasicMetaTransaction {
mapping(address => uint256) metatransactionNonces;

/// @notice Gets the next nonce for a meta-transaction
/// @param _user The user's address
/// @return nonce The nonce
function getMetatransactionNonce(address _user) public view override returns (uint256 nonce) {
return metatransactionNonces[_user];
}
Expand Down
33 changes: 7 additions & 26 deletions contracts/extensions/EvaluatedExpenditure.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pragma experimental ABIEncoderV2;

import { ColonyExtension } from "./ColonyExtension.sol";
import { BasicMetaTransaction } from "./../common/BasicMetaTransaction.sol";
import { IColony } from "./../colony/IColony.sol";

// ignore-file-swc-108

Expand All @@ -32,6 +31,8 @@ contract EvaluatedExpenditure is ColonyExtension, BasicMetaTransaction {
bool constant ARRAY = true;
mapping(address => uint256) metatransactionNonces;

// Interface overrides

/// @notice Returns the identifier of the extension
/// @return _identifier The extension's identifier
function identifier() public pure override returns (bytes32 _identifier) {
Expand All @@ -44,41 +45,21 @@ contract EvaluatedExpenditure is ColonyExtension, BasicMetaTransaction {
return 6;
}

/// @notice Configures the extension
/// @param _colony The colony in which the extension holds permissions
function install(address _colony) public override auth {
require(address(colony) == address(0x0), "extension-already-installed");

colony = IColony(_colony);
}

/// @notice Called when upgrading the extension
function finishUpgrade() public override auth {}

/// @notice Called when deprecating (or undeprecating) the extension
/// @param _deprecated Indicates whether the extension should be deprecated or undeprecated
function deprecate(bool _deprecated) public override auth {
deprecated = _deprecated;
}

/// @notice Called when uninstalling the extension
function uninstall() public override auth {
selfdestruct(payable(address(colony)));
}

/// @notice Gets the next nonce for a meta-transaction
/// @param _userAddress The user's address
/// @param _user The user's address
/// @return nonce The nonce
function getMetatransactionNonce(
address _userAddress
address _user
) public view override returns (uint256 nonce) {
return metatransactionNonces[_userAddress];
return metatransactionNonces[_user];
}

function incrementMetatransactionNonce(address _user) internal override {
metatransactionNonces[_user] += 1;
}

// Public

/// @notice Sets the payout modifiers in given expenditure slots, using the arbitration permission
/// @param _permissionDomainId The domainId in which the extension has the arbitration permission
/// @param _childSkillIndex The index that the `_domainId` is relative to `_permissionDomainId`
Expand Down
21 changes: 2 additions & 19 deletions contracts/extensions/FundingQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ pragma experimental ABIEncoderV2;
import { ColonyDataTypes } from "./../colony/ColonyDataTypes.sol";
import { IColonyNetwork } from "./../colonyNetwork/IColonyNetwork.sol";
import { BasicMetaTransaction } from "./../common/BasicMetaTransaction.sol";
import { ERC20Extended } from "./../common/ERC20Extended.sol";
import { ITokenLocking } from "./../tokenLocking/ITokenLocking.sol";
import { ColonyExtension } from "./ColonyExtension.sol";
import { IColony } from "./../colony/IColony.sol";

contract FundingQueue is ColonyExtension, BasicMetaTransaction {
// Events
Expand Down Expand Up @@ -104,7 +102,7 @@ contract FundingQueue is ColonyExtension, BasicMetaTransaction {
metatransactionNonces[user]++;
}

// Public functions
// Interface overrides

/// @notice Returns the identifier of the extension
/// @return _identifier The extension's identifier
Expand All @@ -121,30 +119,15 @@ contract FundingQueue is ColonyExtension, BasicMetaTransaction {
/// @notice Configures the extension
/// @param _colony The colony in which the extension holds permissions
function install(address _colony) public override auth {
require(address(colony) == address(0x0), "extension-already-installed");
super.install(_colony);

colony = IColony(_colony);
colonyNetwork = IColonyNetwork(colony.getColonyNetwork());
tokenLocking = ITokenLocking(colonyNetwork.getTokenLocking());
token = colony.getToken();

proposals[HEAD].totalSupport = UINT256_MAX; // Initialize queue
}

/// @notice Called when upgrading the extension
function finishUpgrade() public override auth {} // solhint-disable-line no-empty-blocks

/// @notice Called when deprecating (or undeprecating) the extension
/// @param _deprecated Indicates whether the extension should be deprecated or undeprecated
function deprecate(bool _deprecated) public override auth {
deprecated = _deprecated;
}

/// @notice Called when uninstalling the extension
function uninstall() public override auth {
selfdestruct(payable(address(colony)));
}

// Public

/// @notice Create a new funding proposal
Expand Down
10 changes: 10 additions & 0 deletions contracts/extensions/IColonyExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,26 @@ pragma experimental ABIEncoderV2;
import { IBasicMetaTransaction } from "./../common/IBasicMetaTransaction.sol";

interface IColonyExtension is IBasicMetaTransaction {
/// @notice Returns the identifier of the extension
/// @return _identifier The extension's identifier
function identifier() external pure returns (bytes32);

/// @notice Returns the version of the extension
/// @return _version The extension's version number
function version() external pure virtual returns (uint256);

/// @notice Configures the extension
/// @param _colony The colony in which the extension holds permissions
function install(address _colony) external virtual;

/// @notice Called when upgrading the extension (can be a no-op)
function finishUpgrade() external virtual;

/// @notice Called when deprecating (or undeprecating) the extension
/// @param _deprecated Indicates whether the extension should be deprecated or undeprecated
function deprecate(bool _deprecated) external virtual;

/// @notice Called when uninstalling the extension
function uninstall() external virtual;

function getCapabilityRoles(bytes4 _sig) external view virtual returns (bytes32);
Expand Down
33 changes: 10 additions & 23 deletions contracts/extensions/OneTxPayment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
pragma solidity 0.8.25;
pragma experimental ABIEncoderV2;

import { IColony, ColonyDataTypes } from "../colony/IColony.sol";
import { ColonyDataTypes } from "../colony/IColony.sol";
import { ColonyExtension } from "./ColonyExtension.sol";
import { BasicMetaTransaction } from "./../common/BasicMetaTransaction.sol";

Expand All @@ -34,17 +34,19 @@ contract OneTxPayment is ColonyExtension, BasicMetaTransaction {

mapping(address => uint256) metatransactionNonces;

// Interface overrides

/// @notice Gets the next nonce for a meta-transaction
/// @param userAddress The user's address
/// @param _user The user's address
/// @return nonce The nonce
function getMetatransactionNonce(
address userAddress
address _user
) public view override returns (uint256 nonce) {
return metatransactionNonces[userAddress];
return metatransactionNonces[_user];
}

function incrementMetatransactionNonce(address user) internal override {
metatransactionNonces[user]++;
function incrementMetatransactionNonce(address _user) internal override {
metatransactionNonces[_user]++;
}

/// @notice Returns the identifier of the extension
Expand All @@ -59,29 +61,12 @@ contract OneTxPayment is ColonyExtension, BasicMetaTransaction {
return 7;
}

/// @notice Configures the extension
/// @param _colony The colony in which the extension holds permissions
function install(address _colony) public override auth {
require(address(colony) == address(0x0), "extension-already-installed");

colony = IColony(_colony);
}

/// @notice Called when upgrading the extension
function finishUpgrade() public override auth {
// Check colony has been upgraded first
require(colony.version() >= 14, "voting-rep-upgrade-colony-first");
} // solhint-disable-line no-empty-blocks

/// @notice Called when deprecating (or undeprecating) the extension
/// @param _deprecated Indicates whether the extension should be deprecated or undeprecated
function deprecate(bool _deprecated) public override auth {} // solhint-disable-line no-empty-blocks

/// @notice Called when uninstalling the extension
function uninstall() public override auth {
selfdestruct(payable(address(colony)));
}

bytes4 constant MAKE_PAYMENT_SIG =
bytes4(
keccak256(
Expand Down Expand Up @@ -114,6 +99,8 @@ contract OneTxPayment is ColonyExtension, BasicMetaTransaction {
}
}

// Public

/// @notice Completes a colony payment in a single transaction
/// @dev Assumes that each entity holds administration and funding roles in the root domain
/// @param _permissionDomainId The domainId in which the _contract_ has permissions to add a payment and fund it
Expand Down
18 changes: 5 additions & 13 deletions contracts/extensions/ReputationBootstrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ERC20 } from "./../../lib/dappsys/erc20.sol";
import { IReputationMiningCycle } from "./../reputationMiningCycle/IReputationMiningCycle.sol";
import { IColonyNetwork } from "./../colonyNetwork/IColonyNetwork.sol";
import { ColonyExtensionMeta } from "./ColonyExtensionMeta.sol";
import { IColony, ColonyDataTypes } from "./../colony/IColony.sol";
import { ColonyDataTypes } from "./../colony/IColony.sol";

// ignore-file-swc-108

Expand Down Expand Up @@ -67,24 +67,24 @@ contract ReputationBootstrapper is ColonyExtensionMeta {
_;
}

// Overrides
// Interface overrides

/// @notice Returns the identifier of the extension
function identifier() public pure override returns (bytes32) {
return keccak256("ReputationBootstrapper");
}

/// @notice Returns the version of the extension
/// @return _version The extension's version number
function version() public pure override returns (uint256) {
return 4;
}

/// @notice Configures the extension
/// @param _colony The colony in which the extension holds permissions
function install(address _colony) public override auth {
require(address(colony) == address(0x0), "extension-already-installed");
super.install(_colony);

colony = IColony(_colony);
token = colony.getToken();

address colonyNetwork = colony.getColonyNetwork();
Expand All @@ -93,14 +93,6 @@ contract ReputationBootstrapper is ColonyExtensionMeta {
(decayNumerator, decayDenominator) = IReputationMiningCycle(repCycle).getDecayConstant();
}

/// @notice Called when upgrading the extension
function finishUpgrade() public override auth {}

/// @notice Called when deprecating (or undeprecating) the extension
function deprecate(bool _deprecated) public override auth {
deprecated = _deprecated;
}

/// @notice Called when uninstalling the extension
function uninstall() public override auth {
uint256 balance = ERC20(token).balanceOf(address(this));
Expand All @@ -109,7 +101,7 @@ contract ReputationBootstrapper is ColonyExtensionMeta {
"reputation-bootstrapper-transfer-failed"
);

selfdestruct(payable(address(colony)));
super.uninstall();
}

// Public
Expand Down
Loading

0 comments on commit 6181c43

Please sign in to comment.