Skip to content

Commit

Permalink
Add multicall to ColonyExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Oct 7, 2022
1 parent 3a089da commit 5ff012b
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 112 deletions.
3 changes: 2 additions & 1 deletion contracts/extensions/ColonyExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ pragma experimental ABIEncoderV2;

import "./../../lib/dappsys/math.sol";
import "./../common/EtherRouter.sol";
import "./../common/Multicall.sol";
import "./../colony/IColony.sol";
import "./../colony/ColonyDataTypes.sol";


abstract contract ColonyExtension is DSAuth, DSMath {
abstract contract ColonyExtension is DSAuth, DSMath, Multicall {

uint256 constant UINT256_MAX = 2**256 - 1;

Expand Down
2 changes: 1 addition & 1 deletion contracts/extensions/EvaluatedExpenditure.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract EvaluatedExpenditure is ColonyExtension, BasicMetaTransaction {

/// @notice Returns the version of the extension
function version() public override pure returns (uint256) {
return 2;
return 3;
}

/// @notice Configures the extension
Expand Down
2 changes: 1 addition & 1 deletion contracts/extensions/FundingQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ contract FundingQueue is ColonyExtension, PatriciaTreeProofs, BasicMetaTransacti

/// @notice Returns the version of the extension
function version() public override pure returns (uint256) {
return 3;
return 4;
}

/// @notice Configures the extension
Expand Down
1 change: 1 addition & 0 deletions contracts/extensions/IColonyExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ interface IColonyExtension is IBasicMetaTransaction {

function getColony() external view returns(address);

function multicall(bytes[] calldata) external virtual returns (bytes [] memory results);
}
2 changes: 1 addition & 1 deletion contracts/extensions/OneTxPayment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract OneTxPayment is ColonyExtension, BasicMetaTransaction {
/// @notice Returns the version of the extension
/// @return _version The extension's version number
function version() public override pure returns (uint256 _version) {
return 3;
return 4;
}

/// @notice Configures the extension
Expand Down
2 changes: 1 addition & 1 deletion contracts/extensions/TokenSupplier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract TokenSupplier is ColonyExtension, BasicMetaTransaction {

/// @notice Returns the version of the extension
function version() public override pure returns (uint256) {
return 3;
return 4;
}

/// @notice Configures the extension
Expand Down
2 changes: 1 addition & 1 deletion contracts/extensions/Whitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract Whitelist is ColonyExtension, BasicMetaTransaction {
/// @notice Returns the version of the extension
/// @return _version The extension's version number
function version() public override pure returns (uint256 _version) {
return 2;
return 3;
}

/// @notice Configures the extension
Expand Down
36 changes: 0 additions & 36 deletions contracts/extensions/votingReputation/IVotingReputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,6 @@ interface IVotingReputation is IColonyExtension, VotingReputationDataTypes {
)
external;

/// @notice Create a motion in the root domain (DEPRECATED)
/// @param _altTarget The contract to which we send the action (0x0 for the colony)
/// @param _action A bytes array encoding a function call
/// @param _key Reputation tree key for the root domain
/// @param _value Reputation tree value for the root domain
/// @param _branchMask The branchmask of the proof
/// @param _siblings The siblings of the proof
function createRootMotion(
address _altTarget,
bytes memory _action,
bytes memory _key,
bytes memory _value,
uint256 _branchMask,
bytes32[] memory _siblings
)
external;

/// @notice Create a motion in any domain (DEPRECATED)
/// @param _domainId The domain where we vote on the motion
/// @param _childSkillIndex The childSkillIndex pointing to the domain of the action
/// @param _action A bytes array encoding a function call
/// @param _key Reputation tree key for the domain
/// @param _value Reputation tree value for the domain
/// @param _branchMask The branchmask of the proof
/// @param _siblings The siblings of the proof
function createDomainMotion(
uint256 _domainId,
uint256 _childSkillIndex,
bytes memory _action,
bytes memory _key,
bytes memory _value,
uint256 _branchMask,
bytes32[] memory _siblings
)
external;

/// @notice Stake on a motion
/// @param _motionId The id of the motion
/// @param _permissionDomainId The domain where the extension has the arbitration permission
Expand Down
27 changes: 0 additions & 27 deletions contracts/extensions/votingReputation/VotingReputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -257,33 +257,6 @@ contract VotingReputation is ColonyExtension, PatriciaTreeProofs, BasicMetaTrans
emit MotionCreated(motionCount, msgSender(), _domainId);
}

function createRootMotion(
address _altTarget,
bytes memory _action,
bytes memory _key,
bytes memory _value,
uint256 _branchMask,
bytes32[] memory _siblings
)
public
{
createMotion(1, UINT256_MAX, _altTarget, _action, _key, _value, _branchMask, _siblings);
}

function createDomainMotion(
uint256 _domainId,
uint256 _childSkillIndex,
bytes memory _action,
bytes memory _key,
bytes memory _value,
uint256 _branchMask,
bytes32[] memory _siblings
)
public
{
createMotion(_domainId, _childSkillIndex, address(0x0), _action, _key, _value, _branchMask, _siblings);
}

function stakeMotion(
uint256 _motionId,
uint256 _permissionDomainId,
Expand Down
1 change: 1 addition & 0 deletions contracts/testHelpers/GasGuzzler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

pragma solidity 0.7.3;
pragma experimental ABIEncoderV2;

import "./../extensions/ColonyExtensionMeta.sol";

Expand Down
35 changes: 0 additions & 35 deletions docs/interfaces/votingreputation.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,6 @@ Create the action that should be taken based on the passed action to appropriate
|---|---|---|
|_delayAction|bytes|The delay action

### `createDomainMotion(uint256 _domainId, uint256 _childSkillIndex, bytes memory _action, bytes memory _key, bytes memory _value, uint256 _branchMask, bytes32[] memory _siblings)`

Create a motion in any domain (DEPRECATED)


**Parameters**

|Name|Type|Description|
|---|---|---|
|_domainId|uint256|The domain where we vote on the motion
|_childSkillIndex|uint256|The childSkillIndex pointing to the domain of the action
|_action|bytes|A bytes array encoding a function call
|_key|bytes|Reputation tree key for the domain
|_value|bytes|Reputation tree value for the domain
|_branchMask|uint256|The branchmask of the proof
|_siblings|bytes32[]|The siblings of the proof


### `createMotion(uint256 _domainId, uint256 _childSkillIndex, address _altTarget, bytes memory _action, bytes memory _key, bytes memory _value, uint256 _branchMask, bytes32[] memory _siblings)`

Create a motion
Expand All @@ -95,23 +77,6 @@ Create a motion
|_siblings|bytes32[]|The siblings of the proof


### `createRootMotion(address _altTarget, bytes memory _action, bytes memory _key, bytes memory _value, uint256 _branchMask, bytes32[] memory _siblings)`

Create a motion in the root domain (DEPRECATED)


**Parameters**

|Name|Type|Description|
|---|---|---|
|_altTarget|address|The contract to which we send the action (0x0 for the colony)
|_action|bytes|A bytes array encoding a function call
|_key|bytes|Reputation tree key for the root domain
|_value|bytes|Reputation tree value for the root domain
|_branchMask|uint256|The branchmask of the proof
|_siblings|bytes32[]|The siblings of the proof


### `escalateMotion(uint256 _motionId, uint256 _newDomainId, uint256 _childSkillIndex, bytes memory _key, bytes memory _value, uint256 _branchMask, bytes32[] memory _siblings)`

Escalate a motion to a higher domain
Expand Down
35 changes: 27 additions & 8 deletions test/extensions/voting-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,6 @@ contract("Voting Reputation", (accounts) => {
await checkErrorRevert(voting.createMotion(1, 1, ADDRESS_ZERO, action, key, value, mask, siblings), "voting-rep-invalid-domain-id");
});

it("can create a motion using the deprecated interfaces", async () => {
const rootAction = await encodeTxData(colony, "mintTokens", [WAD]);
const domainAction = await encodeTxData(colony, "makeTask", [1, UINT256_MAX, FAKE, 1, 0, 0]);

await voting.createRootMotion(ADDRESS_ZERO, rootAction, domain1Key, domain1Value, domain1Mask, domain1Siblings);
await voting.createDomainMotion(1, UINT256_MAX, domainAction, domain1Key, domain1Value, domain1Mask, domain1Siblings);
});

it("when creating a motion for moveFundsBetweenPots, permissions are correctly respected", async () => {
// Move funds between domain 2 and domain 3 pots using the old deprecated function
// This should not be allowed - it doesn't conform to the standard permission proofs, and so can't
Expand Down Expand Up @@ -2039,6 +2031,33 @@ contract("Voting Reputation", (accounts) => {
it("cannot claim rewards before a motion is finalized", async () => {
await checkErrorRevert(voting.claimReward(motionId, 1, UINT256_MAX, USER0, YAY), "voting-rep-motion-not-claimable");
});

it("can finalize and claim in one transaction via multicall", async () => {
await voting.stakeMotion(motionId, 1, UINT256_MAX, YAY, REQUIRED_STAKE, user0Key, user0Value, user0Mask, user0Siblings, { from: USER0 });
await voting.stakeMotion(motionId, 1, UINT256_MAX, NAY, REQUIRED_STAKE, user1Key, user1Value, user1Mask, user1Siblings, { from: USER1 });

await voting.submitVote(motionId, soliditySha3(SALT, YAY), user0Key, user0Value, user0Mask, user0Siblings, { from: USER0 });

await forwardTime(SUBMIT_PERIOD, this);

await voting.revealVote(motionId, SALT, YAY, user0Key, user0Value, user0Mask, user0Siblings, { from: USER0 });

await forwardTime(REVEAL_PERIOD, this);
await forwardTime(ESCALATION_PERIOD, this);

const finalizeData = await voting.contract.methods.finalizeMotion(motionId).encodeABI();
const claimData = await voting.contract.methods.claimReward(motionId, 1, UINT256_MAX, USER0, YAY).encodeABI();

const user0LockPre = await tokenLocking.getUserLock(token.address, USER0);
await voting.multicall([finalizeData, claimData]);
const user0LockPost = await tokenLocking.getUserLock(token.address, USER0);

const votingPayout = await voting.getVoterReward(motionId, new BN(user0Value.slice(2, 66), 16));

const loserStake = REQUIRED_STAKE.sub(votingPayout); // Take out voter comp

expect(new BN(user0LockPost.balance).sub(new BN(user0LockPre.balance))).to.eq.BN(loserStake.add(REQUIRED_STAKE));
});
});

describe("escalating motions", async () => {
Expand Down

0 comments on commit 5ff012b

Please sign in to comment.