@@ -5,13 +5,14 @@ import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
5
5
import "./CurveInterface.sol " ;
6
6
import "openzeppelin-solidity/contracts/cryptography/ECDSA.sol " ;
7
7
import "openzeppelin-solidity/contracts/math/SafeMath.sol " ;
8
+ import "./Agreement.sol " ;
8
9
9
10
/**
10
11
* @title A scheme for reputation allocation according to token balances
11
12
* This contract is assuming that the token contract is paused, and one cannot transfer its tokens.
12
13
*/
13
14
14
- contract ReputationFromToken {
15
+ contract ReputationFromToken is Agreement {
15
16
using ECDSA for bytes32 ;
16
17
using SafeMath for uint256 ;
17
18
@@ -26,32 +27,36 @@ contract ReputationFromToken {
26
27
bytes32 public constant DELEGATION_HASH_EIP712 =
27
28
keccak256 (abi.encodePacked (
28
29
"address ReputationFromTokenAddress " ,
29
- "address Beneficiary "
30
+ "address Beneficiary " ,
31
+ "bytes32 AgreementHash "
30
32
));
31
33
32
34
event Redeem (address indexed _beneficiary , address indexed _sender , uint256 _amount );
33
-
35
+
34
36
/**
35
37
* @dev initialize
36
38
* @param _avatar the avatar to mint reputation from
37
39
* @param _tokenContract the token contract
40
+ * @param _agreementHash is a hash of agreement required to be added to the TX by participants
38
41
*/
39
- function initialize (Avatar _avatar , IERC20 _tokenContract , CurveInterface _curve ) external
42
+ function initialize (Avatar _avatar , IERC20 _tokenContract , CurveInterface _curve , bytes32 _agreementHash ) external
40
43
{
41
44
require (avatar == Avatar (0 ), "can be called only one time " );
42
45
require (_avatar != Avatar (0 ), "avatar cannot be zero " );
43
46
tokenContract = _tokenContract;
44
47
avatar = _avatar;
45
48
curve = _curve;
49
+ super .setAgreementHash (_agreementHash);
46
50
}
47
51
48
52
/**
49
53
* @dev redeem function
50
54
* @param _beneficiary the beneficiary address to redeem for
55
+ * @param _agreementHash the agreementHash hash
51
56
* @return uint256 minted reputation
52
57
*/
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 );
55
60
}
56
61
57
62
/**
@@ -65,6 +70,7 @@ contract ReputationFromToken {
65
70
*/
66
71
function redeemWithSignature (
67
72
address _beneficiary ,
73
+ bytes32 _agreementHash ,
68
74
uint256 _signatureType ,
69
75
bytes calldata _signature
70
76
)
@@ -79,20 +85,22 @@ contract ReputationFromToken {
79
85
DELEGATION_HASH_EIP712, keccak256 (
80
86
abi.encodePacked (
81
87
address (this ),
82
- _beneficiary)
88
+ _beneficiary,
89
+ _agreementHash)
83
90
)
84
91
)
85
92
);
86
93
} else {
87
94
delegationDigest = keccak256 (
88
95
abi.encodePacked (
89
96
address (this ),
90
- _beneficiary)
97
+ _beneficiary,
98
+ _agreementHash)
91
99
).toEthSignedMessageHash ();
92
100
}
93
101
address redeemer = delegationDigest.recover (_signature);
94
102
require (redeemer != address (0 ), "redeemer address cannot be 0 " );
95
- return _redeem (_beneficiary, redeemer);
103
+ return _redeem (_beneficiary, redeemer, _agreementHash );
96
104
}
97
105
98
106
/**
@@ -101,7 +109,10 @@ contract ReputationFromToken {
101
109
* @param _redeemer the redeemer address
102
110
* @return uint256 minted reputation
103
111
*/
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 ) {
105
116
require (avatar != Avatar (0 ), "should initialize first " );
106
117
require (redeems[_redeemer] == false , "redeeming twice from the same account is not allowed " );
107
118
redeems[_redeemer] = true ;
0 commit comments