Skip to content

Commit a920a38

Browse files
authored
reputationFromToken: add agreement (#689)
* reputationFromToken: add agreementHash * bum version to rc33
1 parent 69f5e33 commit a920a38

File tree

4 files changed

+97
-67
lines changed

4 files changed

+97
-67
lines changed

contracts/schemes/ReputationFromToken.sol

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
55
import "./CurveInterface.sol";
66
import "openzeppelin-solidity/contracts/cryptography/ECDSA.sol";
77
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
8+
import "./Agreement.sol";
89

910
/**
1011
* @title A scheme for reputation allocation according to token balances
1112
* This contract is assuming that the token contract is paused, and one cannot transfer its tokens.
1213
*/
1314

14-
contract ReputationFromToken {
15+
contract ReputationFromToken is Agreement {
1516
using ECDSA for bytes32;
1617
using SafeMath for uint256;
1718

@@ -26,32 +27,36 @@ contract ReputationFromToken {
2627
bytes32 public constant DELEGATION_HASH_EIP712 =
2728
keccak256(abi.encodePacked(
2829
"address ReputationFromTokenAddress",
29-
"address Beneficiary"
30+
"address Beneficiary",
31+
"bytes32 AgreementHash"
3032
));
3133

3234
event Redeem(address indexed _beneficiary, address indexed _sender, uint256 _amount);
33-
35+
3436
/**
3537
* @dev initialize
3638
* @param _avatar the avatar to mint reputation from
3739
* @param _tokenContract the token contract
40+
* @param _agreementHash is a hash of agreement required to be added to the TX by participants
3841
*/
39-
function initialize(Avatar _avatar, IERC20 _tokenContract, CurveInterface _curve) external
42+
function initialize(Avatar _avatar, IERC20 _tokenContract, CurveInterface _curve, bytes32 _agreementHash) external
4043
{
4144
require(avatar == Avatar(0), "can be called only one time");
4245
require(_avatar != Avatar(0), "avatar cannot be zero");
4346
tokenContract = _tokenContract;
4447
avatar = _avatar;
4548
curve = _curve;
49+
super.setAgreementHash(_agreementHash);
4650
}
4751

4852
/**
4953
* @dev redeem function
5054
* @param _beneficiary the beneficiary address to redeem for
55+
* @param _agreementHash the agreementHash hash
5156
* @return uint256 minted reputation
5257
*/
53-
function redeem(address _beneficiary) external returns(uint256) {
54-
return _redeem(_beneficiary, msg.sender);
58+
function redeem(address _beneficiary, bytes32 _agreementHash) external returns(uint256) {
59+
return _redeem(_beneficiary, msg.sender, _agreementHash);
5560
}
5661

5762
/**
@@ -65,6 +70,7 @@ contract ReputationFromToken {
6570
*/
6671
function redeemWithSignature(
6772
address _beneficiary,
73+
bytes32 _agreementHash,
6874
uint256 _signatureType,
6975
bytes calldata _signature
7076
)
@@ -79,20 +85,22 @@ contract ReputationFromToken {
7985
DELEGATION_HASH_EIP712, keccak256(
8086
abi.encodePacked(
8187
address(this),
82-
_beneficiary)
88+
_beneficiary,
89+
_agreementHash)
8390
)
8491
)
8592
);
8693
} else {
8794
delegationDigest = keccak256(
8895
abi.encodePacked(
8996
address(this),
90-
_beneficiary)
97+
_beneficiary,
98+
_agreementHash)
9199
).toEthSignedMessageHash();
92100
}
93101
address redeemer = delegationDigest.recover(_signature);
94102
require(redeemer != address(0), "redeemer address cannot be 0");
95-
return _redeem(_beneficiary, redeemer);
103+
return _redeem(_beneficiary, redeemer, _agreementHash);
96104
}
97105

98106
/**
@@ -101,7 +109,10 @@ contract ReputationFromToken {
101109
* @param _redeemer the redeemer address
102110
* @return uint256 minted reputation
103111
*/
104-
function _redeem(address _beneficiary, address _redeemer) private returns(uint256) {
112+
function _redeem(address _beneficiary, address _redeemer, bytes32 _agreementHash)
113+
private
114+
onlyAgree(_agreementHash)
115+
returns(uint256) {
105116
require(avatar != Avatar(0), "should initialize first");
106117
require(redeems[_redeemer] == false, "redeeming twice from the same account is not allowed");
107118
redeems[_redeemer] = true;

package-lock.json

Lines changed: 51 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@daostack/arc",
3-
"version": "0.0.1-rc.32",
3+
"version": "0.0.1-rc.33",
44
"description": "A platform for building DAOs",
55
"files": [
66
"contracts/",

0 commit comments

Comments
 (0)