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 12, 2022
1 parent ce7c65e commit 52e18fd
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 114 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 @@ -41,7 +41,7 @@ contract EvaluatedExpenditure 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
2 changes: 1 addition & 1 deletion contracts/extensions/FundingQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ contract FundingQueue is ColonyExtension, PatriciaTreeProofs, BasicMetaTransacti
/// @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
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 @@ -72,7 +72,7 @@ contract TokenSupplier 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/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/extensions/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
4 changes: 2 additions & 2 deletions test-smoke/colony-storage-consistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ contract("Contract Storage", (accounts) => {
console.log("miningCycleStateHash:", miningCycleStateHash);
console.log("tokenLockingStateHash:", tokenLockingStateHash);

expect(colonyNetworkStateHash).to.equal("0x5301b90fa68f64f43f34a20e544e6122fc9ec798019f759c5468041335d4120b");
expect(colonyStateHash).to.equal("0x0d505f903d784b2bf2993a7c90eb6b78aa2e5f3ba0a10805a8efc950e5c09c11");
expect(colonyNetworkStateHash).to.equal("0xf4bc527a51bee9565b692b4db2d018f2adbc8b76518cbc5fc9cbc639a4afa23d");
expect(colonyStateHash).to.equal("0xdd6a69be4626fc8376f6a48e7ed615fb77eaa62a62a9b80fd25bd69382acd268");
expect(metaColonyStateHash).to.equal("0x020fc4d7bb927c5a8fabb5aed304281c7a90f41f4a62c247570a8446037056cd");
expect(miningCycleStateHash).to.equal("0x63723c9783b0f0c20e8640fc383ed40dbc228a93cc73a18fa6c6e5f0c38e8694");
expect(tokenLockingStateHash).to.equal("0xa4dd9734ad2f6b18ec82a5d10be671a5082d6400173d47ac1401580f57cd1638");
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 52e18fd

Please sign in to comment.