Skip to content

Commit f520243

Browse files
committed
Add ability to slash expenditure stakes
1 parent b6f8091 commit f520243

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

contracts/extensions/ExpenditureUtils.sol

+21-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ contract ExpenditureUtils is ColonyExtensionMeta, PatriciaTreeProofs {
3737
// Modifiers
3838

3939
modifier onlyRoot() {
40-
require(colony.hasUserRole(msgSender(), 1, ColonyDataTypes.ColonyRole.Root), "voting-rep-caller-not-root");
40+
require(colony.hasUserRole(msgSender(), 1, ColonyDataTypes.ColonyRole.Root), "evaluated-expenditure-caller-not-root");
4141
_;
4242
}
4343

@@ -102,6 +102,26 @@ contract ExpenditureUtils is ColonyExtensionMeta, PatriciaTreeProofs {
102102
colony.transferExpenditure(expenditureId, msgSender());
103103
}
104104

105+
function slashStake(
106+
uint256 _permissionDomainId,
107+
uint256 _childSkillIndex,
108+
uint256 _expenditureId
109+
)
110+
public
111+
{
112+
ColonyDataTypes.Expenditure memory expenditure = colony.getExpenditure(_expenditureId);
113+
uint256 stake = stakes[expenditure.owner][_expenditureId];
114+
require(stake > 0, "expenditure-utils-nothing-to-claim");
115+
116+
require(
117+
colony.hasInheritedUserRole(msgSender(), _permissionDomainId, ColonyDataTypes.ColonyRole.Arbitration, _childSkillIndex, expenditure.domainId),
118+
"expenditure-utils-caller-not-arbitration"
119+
);
120+
121+
delete stakes[expenditure.owner][_expenditureId];
122+
colony.transferStake(_permissionDomainId, _childSkillIndex, address(this), expenditure.owner, expenditure.domainId, stake, address(0x0));
123+
}
124+
105125
function reclaimStake(uint256 _expenditureId) public {
106126
uint256 stake = stakes[msgSender()][_expenditureId];
107127
require(stake > 0, "expenditure-utils-nothing-to-claim");

test/extensions/expenditure-utils.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ contract("ExpenditureUtils", (accounts) => {
113113
});
114114
});
115115

116-
describe.only("using stakes to manage expenditures", async () => {
116+
describe("using stakes to manage expenditures", async () => {
117117
beforeEach(async () => {
118118
await expenditureUtils.setStakeFraction(WAD.divn(10)); // Stake of .3 WADs
119119

@@ -134,6 +134,19 @@ contract("ExpenditureUtils", (accounts) => {
134134
expect(obligation).to.eq.BN(WAD.muln(3).divn(10));
135135
});
136136

137+
it("can slash the stake with the arbitration permission", async () => {
138+
await expenditureUtils.makeExpenditureWithStake(1, UINT256_MAX, 1, domain1Key, domain1Value, domain1Mask, domain1Siblings, { from: USER0 });
139+
const expenditureId = await colony.getExpenditureCount();
140+
141+
await expenditureUtils.slashStake(1, UINT256_MAX, expenditureId);
142+
143+
const obligation = await tokenLocking.getObligation(USER0, token.address, colony.address);
144+
expect(obligation).to.be.zero;
145+
146+
const userLock = await tokenLocking.getUserLock(token.address, USER0);
147+
expect(userLock.balance).to.eq.BN(WAD.sub(WAD.muln(3).divn(10)));
148+
});
149+
137150
it("can reclaim the stake by cancelling the expenditure", async () => {
138151
await expenditureUtils.makeExpenditureWithStake(1, UINT256_MAX, 1, domain1Key, domain1Value, domain1Mask, domain1Siblings, { from: USER0 });
139152
const expenditureId = await colony.getExpenditureCount();
@@ -144,6 +157,9 @@ contract("ExpenditureUtils", (accounts) => {
144157

145158
const obligation = await tokenLocking.getObligation(USER0, token.address, colony.address);
146159
expect(obligation).to.be.zero;
160+
161+
const userLock = await tokenLocking.getUserLock(token.address, USER0);
162+
expect(userLock.balance).to.eq.BN(WAD);
147163
});
148164

149165
it("can reclaim the stake by finalizing the expenditure", async () => {
@@ -156,6 +172,9 @@ contract("ExpenditureUtils", (accounts) => {
156172

157173
const obligation = await tokenLocking.getObligation(USER0, token.address, colony.address);
158174
expect(obligation).to.be.zero;
175+
176+
const userLock = await tokenLocking.getUserLock(token.address, USER0);
177+
expect(userLock.balance).to.eq.BN(WAD);
159178
});
160179

161180
it("cannot reclaim the stake while the expenditure is in progress", async () => {

0 commit comments

Comments
 (0)