-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from varasev/update-ERC677BridgeToken
Extend ERC677BridgeToken contract for `xDai-POA` bridge
- Loading branch information
Showing
9 changed files
with
320 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
pragma solidity 0.4.24; | ||
|
||
import "./ERC677BridgeToken.sol"; | ||
|
||
|
||
contract ERC677BridgeTokenRewardable is ERC677BridgeToken { | ||
|
||
address public blockRewardContract; | ||
address public validatorSetContract; | ||
|
||
constructor( | ||
string _name, | ||
string _symbol, | ||
uint8 _decimals | ||
) public ERC677BridgeToken(_name, _symbol, _decimals) {} | ||
|
||
function setBlockRewardContract(address _blockRewardContract) onlyOwner public { | ||
require(_blockRewardContract != address(0) && isContract(_blockRewardContract)); | ||
blockRewardContract = _blockRewardContract; | ||
} | ||
|
||
function setValidatorSetContract(address _validatorSetContract) onlyOwner public { | ||
require(_validatorSetContract != address(0) && isContract(_validatorSetContract)); | ||
validatorSetContract = _validatorSetContract; | ||
} | ||
|
||
modifier onlyBlockRewardContract() { | ||
require(msg.sender == blockRewardContract); | ||
_; | ||
} | ||
|
||
modifier onlyValidatorSetContract() { | ||
require(msg.sender == validatorSetContract); | ||
_; | ||
} | ||
|
||
function mintReward(address[] _receivers, uint256[] _rewards) external onlyBlockRewardContract { | ||
for (uint256 i = 0; i < _receivers.length; i++) { | ||
address to = _receivers[i]; | ||
uint256 amount = _rewards[i]; | ||
|
||
// Mint `amount` for `to` | ||
totalSupply_ = totalSupply_.add(amount); | ||
balances[to] = balances[to].add(amount); | ||
emit Mint(to, amount); | ||
emit Transfer(address(0), to, amount); | ||
} | ||
} | ||
|
||
function stake(address _staker, uint256 _amount) external onlyValidatorSetContract { | ||
// Transfer `_amount` from `_staker` to `validatorSetContract` | ||
require(_amount <= balances[_staker]); | ||
balances[_staker] = balances[_staker].sub(_amount); | ||
balances[validatorSetContract] = balances[validatorSetContract].add(_amount); | ||
emit Transfer(_staker, validatorSetContract, _amount); | ||
} | ||
|
||
function withdraw(address _staker, uint256 _amount) external onlyValidatorSetContract { | ||
// Transfer `_amount` from `validatorSetContract` to `_staker` | ||
require(_amount <= balances[validatorSetContract]); | ||
balances[validatorSetContract] = balances[validatorSetContract].sub(_amount); | ||
balances[_staker] = balances[_staker].add(_amount); | ||
emit Transfer(validatorSetContract, _staker, _amount); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pragma solidity 0.4.24; | ||
|
||
|
||
contract ValidatorSet { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pragma solidity 0.4.24; | ||
|
||
import '../../contracts/ERC677BridgeTokenRewardable.sol'; | ||
|
||
|
||
contract ERC677BridgeTokenRewardableMock is ERC677BridgeTokenRewardable { | ||
|
||
constructor( | ||
string _name, | ||
string _symbol, | ||
uint8 _decimals | ||
) public ERC677BridgeTokenRewardable(_name, _symbol, _decimals) {} | ||
|
||
function setBlockRewardContractMock(address _blockRewardContract) public { | ||
blockRewardContract = _blockRewardContract; | ||
} | ||
|
||
function setValidatorSetContractMock(address _validatorSetContract) public { | ||
validatorSetContract = _validatorSetContract; | ||
} | ||
|
||
} |
Oops, something went wrong.