Skip to content

Commit a12ab77

Browse files
authored
curation: add a withdrawal fee (#205)
1 parent 1c8cc05 commit a12ab77

File tree

6 files changed

+295
-195
lines changed

6 files changed

+295
-195
lines changed

contracts/Curation.sol

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ pragma experimental ABIEncoderV2;
33

44
/*
55
* @title Curation contract
6-
* @notice Allows Curators to signal Subgraphs that are relevant for indexers and earn fees from the Query Market
6+
* @notice Allows Curators to signal Subgraphs that are relevant for indexers and earn
7+
* fees from the Query Market
78
*/
89

910
import "./Governed.sol";
@@ -40,6 +41,10 @@ contract Curation is Governed, BancorFormula {
4041
// This is the `startPoolBalance` for the bonding curve
4142
uint256 public minimumCurationStake;
4243

44+
// Fee charged when curator withdraw stake
45+
// Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
46+
uint256 public withdrawalFeePercentage;
47+
4348
// Mapping of subgraphID => Subgraph
4449
mapping(bytes32 => Subgraph) public subgraphs;
4550

@@ -65,12 +70,14 @@ contract Curation is Governed, BancorFormula {
6570
/**
6671
* @dev Emitted when `curator` redeemed `shares` for a `subgraphID`.
6772
* The curator will receive `tokens` according to the value of the bonding curve.
73+
* An amount of `withdrawalFees` will be collected and burned.
6874
*/
6975
event Redeemed(
7076
address indexed curator,
7177
bytes32 indexed subgraphID,
7278
uint256 tokens,
73-
uint256 shares
79+
uint256 shares,
80+
uint256 withdrawalFees
7481
);
7582

7683
/**
@@ -151,6 +158,20 @@ contract Curation is Governed, BancorFormula {
151158
emit ParameterUpdated("minimumCurationStake");
152159
}
153160

161+
/**
162+
* @dev Set the fee percentage to charge when a curator withdraws stake
163+
* @param _percentage Percentage fee charged when withdrawing stake
164+
*/
165+
function setWithdrawalFeePercentage(uint256 _percentage) external onlyGovernor {
166+
// Must be within 0% to 100% (inclusive)
167+
require(
168+
_percentage <= MAX_PPM,
169+
"Withdrawal fee percentage must be below or equal to MAX_PPM"
170+
);
171+
withdrawalFeePercentage = _percentage;
172+
emit ParameterUpdated("withdrawalFeePercentage");
173+
}
174+
154175
/**
155176
* @dev Assign Graph Tokens received from staking to the subgraph reserve
156177
* @param _subgraphID Subgraph where funds should be allocated as reserves
@@ -209,10 +230,17 @@ contract Curation is Governed, BancorFormula {
209230
delete subgraphs[_subgraphID];
210231
}
211232

233+
// Calculate withdrawal fees and burn the tokens
234+
uint256 withdrawalFees = percentageOf(withdrawalFeePercentage, tokens);
235+
if (withdrawalFees > 0) {
236+
tokens = tokens.sub(withdrawalFees);
237+
token.burn(withdrawalFees);
238+
}
239+
212240
// Return the tokens to the curator
213241
require(token.transfer(curator, tokens), "Error sending curator tokens");
214242

215-
emit Redeemed(curator, _subgraphID, tokens, _shares);
243+
emit Redeemed(curator, _subgraphID, tokens, _shares, withdrawalFees);
216244
}
217245

218246
/**
@@ -377,4 +405,14 @@ contract Curation is Governed, BancorFormula {
377405

378406
emit Staked(_curator, _subgraphID, _tokens, shares);
379407
}
408+
409+
/**
410+
* @dev Calculate the percentage for value in parts per million (PPM)
411+
* @param _ppm Parts per million
412+
* @param _value Value to calculate percentage of
413+
* @return Percentage of value
414+
*/
415+
function percentageOf(uint256 _ppm, uint256 _value) private pure returns (uint256) {
416+
return _ppm.mul(_value).div(MAX_PPM);
417+
}
380418
}

migrations/2_deploy_contracts.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ module.exports = async (deployer, network, accounts) => {
7272
'\t> Staking -> Set channelDisputeEpochs: ',
7373
)
7474
await executeAndLog(curation.setStaking(staking.address), '\t> Curation -> Set staking: ')
75+
await executeAndLog(
76+
curation.setWithdrawalFeePercentage(config.curation.withdrawalFeePercentage),
77+
'\t> Curation -> Set withdrawalFeePercentage: ',
78+
)
7579

7680
// Summary
7781
log('\n')

migrations/deploy.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ const TOKEN_UNIT = new BN('10').pow(new BN('18'))
44

55
module.exports = {
66
curation: {
7-
// Reserve ratio to set bonding curve for curation (in PPM)
87
reserveRatio: 500000,
9-
// Minimum amount required to be staked by Curators
108
minimumCurationStake: new BN('100').mul(TOKEN_UNIT),
9+
withdrawalFeePercentage: 50000,
1110
},
1211
dispute: {
1312
minimumDeposit: new BN('100').mul(TOKEN_UNIT),

0 commit comments

Comments
 (0)