11pragma solidity ^ 0.4.25 ;
22
33import "./Locking4Reputation.sol " ;
4+ import "./PriceOracleInterface.sol " ;
45import "openzeppelin-solidity/contracts/ownership/Ownable.sol " ;
6+ import "openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol " ;
57
68
79/**
810 * @title A scheme for locking ERC20 Tokens for reputation
911 */
1012
1113contract LockingToken4Reputation is Locking4Reputation , Ownable {
12- StandardToken public token;
14+
15+ PriceOracleInterface public priceOracleContract;
16+ // lockingId => token
17+ mapping (bytes32 => StandardToken) public lockedTokens;
18+
19+ event LockToken (bytes32 indexed _lockingId , address indexed _token , uint _numerator , uint _denominator );
1320
1421 /**
1522 * @dev initialize
@@ -22,7 +29,8 @@ contract LockingToken4Reputation is Locking4Reputation, Ownable {
2229 * @param _redeemEnableTime redeem enable time .
2330 * redeem reputation can be done after this time.
2431 * @param _maxLockingPeriod maximum locking period allowed.
25- * @param _token the locking token
32+ * @param _priceOracleContract the price oracle contract which the locked token will be
33+ * validated against
2634 */
2735 function initialize (
2836 Avatar _avatar ,
@@ -31,11 +39,11 @@ contract LockingToken4Reputation is Locking4Reputation, Ownable {
3139 uint _lockingEndTime ,
3240 uint _redeemEnableTime ,
3341 uint _maxLockingPeriod ,
34- StandardToken _token )
42+ PriceOracleInterface _priceOracleContract )
3543 external
3644 onlyOwner
3745 {
38- token = _token ;
46+ priceOracleContract = _priceOracleContract ;
3947 super ._initialize (
4048 _avatar,
4149 _reputationReward,
@@ -53,7 +61,7 @@ contract LockingToken4Reputation is Locking4Reputation, Ownable {
5361 */
5462 function release (address _beneficiary ,bytes32 _lockingId ) public returns (bool ) {
5563 uint amount = super ._release (_beneficiary, _lockingId);
56- require (token .transfer (_beneficiary, amount), "transfer should success " );
64+ require (lockedTokens[_lockingId] .transfer (_beneficiary, amount), "transfer should success " );
5765
5866 return true ;
5967 }
@@ -62,12 +70,25 @@ contract LockingToken4Reputation is Locking4Reputation, Ownable {
6270 * @dev lock function
6371 * @param _amount the amount to lock
6472 * @param _period the locking period
73+ * @param _token the token to lock - this should be whitelisted at the priceOracleContract
6574 * @return lockingId
6675 */
67- function lock (uint _amount , uint _period ) public returns (bytes32 ) {
68- require (token.transferFrom (msg .sender , address (this ), _amount), "transferFrom should success " );
76+ function lock (uint _amount , uint _period ,StandardToken _token ) public returns (bytes32 lockingId ) {
6977
70- return super ._lock (_amount, _period, msg .sender );
71- }
78+ uint numerator;
79+ uint denominator;
80+
81+ (numerator,denominator) = priceOracleContract.getPrice (address (_token));
82+
83+ require (numerator > 0 ,"numerator should be > 0 " );
84+ require (denominator > 0 ,"denominator should be > 0 " );
7285
86+ require (_token.transferFrom (msg .sender , address (this ), _amount), "transferFrom should success " );
87+
88+ lockingId = super ._lock (_amount, _period, msg .sender ,numerator,denominator);
89+
90+ lockedTokens[lockingId] = _token;
91+
92+ emit LockToken (lockingId,address (_token),numerator,denominator);
93+ }
7394}
0 commit comments