From 77d2ddd2eddd4dbac3c323a1a94ca594424ac05b Mon Sep 17 00:00:00 2001 From: Hareesh Nagaraj Date: Fri, 1 May 2020 14:33:07 -0400 Subject: [PATCH 1/6] Removing TimeHelpers --- eth-contracts/contracts/res/TimeHelpers.sol | 48 --------------------- eth-contracts/contracts/staking/Staking.sol | 9 ++-- 2 files changed, 4 insertions(+), 53 deletions(-) delete mode 100644 eth-contracts/contracts/res/TimeHelpers.sol diff --git a/eth-contracts/contracts/res/TimeHelpers.sol b/eth-contracts/contracts/res/TimeHelpers.sol deleted file mode 100644 index f4a5d5725d7..00000000000 --- a/eth-contracts/contracts/res/TimeHelpers.sol +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SPDX-License-Identitifer: MIT - */ - -pragma solidity ^0.5.0; - -import "./Uint256Helpers.sol"; - - -contract TimeHelpers { - using Uint256Helpers for uint256; - - /** - * @dev Returns the current block number. - * Using a function rather than `block.number` allows us to easily mock the block number in - * tests. - */ - function getBlockNumber() internal view returns (uint256) { - return block.number; - } - - /** - * @dev Returns the current block number, converted to uint64. - * Using a function rather than `block.number` allows us to easily mock the block number in - * tests. - */ - function getBlockNumber64() internal view returns (uint64) { - return getBlockNumber().toUint64(); - } - - /** - * @dev Returns the current timestamp. - * Using a function rather than `block.timestamp` allows us to easily mock it in - * tests. - */ - function getTimestamp() internal view returns (uint256) { - return block.timestamp; // solium-disable-line security/no-block-members - } - - /** - * @dev Returns the current timestamp, converted to uint64. - * Using a function rather than `block.timestamp` allows us to easily mock it in - * tests. - */ - function getTimestamp64() internal view returns (uint64) { - return getTimestamp().toUint64(); - } -} diff --git a/eth-contracts/contracts/staking/Staking.sol b/eth-contracts/contracts/staking/Staking.sol index fd5e0cda2c8..d3665f00949 100644 --- a/eth-contracts/contracts/staking/Staking.sol +++ b/eth-contracts/contracts/staking/Staking.sol @@ -8,12 +8,11 @@ import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/SafeERC20 import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Burnable.sol"; import "../res/IsContract.sol"; -import "../res/TimeHelpers.sol"; import "../service/registry/RegistryContract.sol"; /** NOTE - will call RegistryContract.constructor, which calls Ownable constructor */ -contract Staking is RegistryContract, ERCStaking, ERCStakingHistory, IsContract, TimeHelpers { +contract Staking is RegistryContract, ERCStaking, ERCStakingHistory, IsContract { using SafeMath for uint256; using Checkpointing for Checkpointing.History; using SafeERC20 for ERC20; @@ -96,7 +95,7 @@ contract Staking is RegistryContract, ERCStaking, ERCStakingHistory, IsContract, bytes("")); // TODO: RM bytes requirement if unused // Update claim history even if no value claimed - accounts[_stakerAccount].claimHistory.add64(getBlockNumber64(), _amount); + accounts[_stakerAccount].claimHistory.add(block.number, _amount); } /** @@ -385,7 +384,7 @@ contract Staking is RegistryContract, ERCStaking, ERCStakingHistory, IsContract, } // add new value to account history - accounts[_accountAddress].stakedHistory.add64(getBlockNumber64(), newStake); + accounts[_accountAddress].stakedHistory.add(block.number, newStake); } function _modifyTotalStaked(uint256 _by, bool _increase) internal { @@ -399,7 +398,7 @@ contract Staking is RegistryContract, ERCStaking, ERCStakingHistory, IsContract, } // add new value to total history - totalStakedHistory.add64(getBlockNumber64(), newStake); + totalStakedHistory.add(block.number, newStake); } function _transfer(address _from, address _to, uint256 _amount) internal { From c84960d4bdb8e5e6f2716a2f528fba1dbf6e1953 Mon Sep 17 00:00:00 2001 From: Hareesh Nagaraj Date: Fri, 1 May 2020 14:37:23 -0400 Subject: [PATCH 2/6] Removing unnecesary contracts --- eth-contracts/contracts/res/Uint256Helpers.sol | 13 ------------- eth-contracts/contracts/staking/Staking.sol | 11 ----------- 2 files changed, 24 deletions(-) delete mode 100644 eth-contracts/contracts/res/Uint256Helpers.sol diff --git a/eth-contracts/contracts/res/Uint256Helpers.sol b/eth-contracts/contracts/res/Uint256Helpers.sol deleted file mode 100644 index 72cb13d464b..00000000000 --- a/eth-contracts/contracts/res/Uint256Helpers.sol +++ /dev/null @@ -1,13 +0,0 @@ -pragma solidity ^0.5.0; - - -library Uint256Helpers { - uint256 private constant MAX_UINT64 = uint64(-1); - - string private constant ERROR_NUMBER_TOO_BIG = "UINT64_NUMBER_TOO_BIG"; - - function toUint64(uint256 a) internal pure returns (uint64) { - require(a <= MAX_UINT64, ERROR_NUMBER_TOO_BIG); - return uint64(a); - } -} diff --git a/eth-contracts/contracts/staking/Staking.sol b/eth-contracts/contracts/staking/Staking.sol index d3665f00949..bdec5c4a132 100644 --- a/eth-contracts/contracts/staking/Staking.sol +++ b/eth-contracts/contracts/staking/Staking.sol @@ -400,15 +400,4 @@ contract Staking is RegistryContract, ERCStaking, ERCStakingHistory, IsContract // add new value to total history totalStakedHistory.add(block.number, newStake); } - - function _transfer(address _from, address _to, uint256 _amount) internal { - // transferring 0 staked tokens is invalid - require(_amount > 0, ERROR_AMOUNT_ZERO); - - // update stakes - _modifyStakeBalance(_from, _amount, false); - _modifyStakeBalance(_to, _amount, true); - - emit StakeTransferred(_from,_amount, _to); - } } From 9223e13cecfb5a80dc756d630b39c0cba5d08e2b Mon Sep 17 00:00:00 2001 From: Hareesh Nagaraj Date: Fri, 1 May 2020 16:11:42 -0400 Subject: [PATCH 3/6] Use ERCStakingInterface everywhere --- .../contracts/service/ClaimsManager.sol | 9 ++++---- .../contracts/service/DelegateManager.sol | 15 ++++++------- .../service/ServiceProviderFactory.sol | 22 +++++++++---------- ...ERCStaking.sol => ERCStakingInterface.sol} | 11 +++++++--- eth-contracts/contracts/staking/Staking.sol | 4 ++-- 5 files changed, 31 insertions(+), 30 deletions(-) rename eth-contracts/contracts/staking/{ERCStaking.sol => ERCStakingInterface.sol} (68%) diff --git a/eth-contracts/contracts/service/ClaimsManager.sol b/eth-contracts/contracts/service/ClaimsManager.sol index d612c540956..44cb88f1ed8 100644 --- a/eth-contracts/contracts/service/ClaimsManager.sol +++ b/eth-contracts/contracts/service/ClaimsManager.sol @@ -1,5 +1,5 @@ pragma solidity ^0.5.0; -import "../staking/Staking.sol"; +import "../staking/ERCStakingInterface.sol"; import "./registry/RegistryContract.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Mintable.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol"; @@ -70,7 +70,6 @@ contract ClaimsManager is RegistryContract { audiusToken = ERC20Mintable(tokenAddress); registry = RegistryInterface(_registryAddress); - fundBlock = 0; fundRoundBlockDiff = 10; fundBlock = 0; fundingAmount = 20 * 10**uint256(DECIMALS); // 20 AUDS = 20 * 10**uint256(DECIMALS) @@ -108,7 +107,7 @@ contract ClaimsManager is RegistryContract { // Permissioned to stakers or contract deployer function initiateRound() external { requireIsInitialized(); - bool senderStaked = Staking( + bool senderStaked = ERCStakingInterface( registry.getContract(stakingProxyOwnerKey) ).totalStakedFor(msg.sender) > 0; @@ -146,7 +145,7 @@ contract ClaimsManager is RegistryContract { ); address stakingAddress = registry.getContract(stakingProxyOwnerKey); - Staking stakingContract = Staking(stakingAddress); + ERCStakingInterface stakingContract = ERCStakingInterface(stakingAddress); // Prevent duplicate claim uint lastUserClaimBlock = stakingContract.lastClaimedFor(_claimer); require(lastUserClaimBlock <= fundBlock, "Claim already processed for user"); @@ -200,7 +199,7 @@ contract ClaimsManager is RegistryContract { } function claimPending(address _sp) external view returns (bool pending) { - uint lastClaimedForSP = Staking( + uint lastClaimedForSP = ERCStakingInterface( registry.getContract(stakingProxyOwnerKey) ).lastClaimedFor(_sp); return (lastClaimedForSP < fundBlock); diff --git a/eth-contracts/contracts/service/DelegateManager.sol b/eth-contracts/contracts/service/DelegateManager.sol index f5e7e3723cd..89a0f682017 100644 --- a/eth-contracts/contracts/service/DelegateManager.sol +++ b/eth-contracts/contracts/service/DelegateManager.sol @@ -6,6 +6,7 @@ import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol import "./registry/RegistryContract.sol"; import "./interface/registry/RegistryInterface.sol"; import "../staking/Staking.sol"; +import "../staking/ERCStakingInterface.sol"; import "./ServiceProviderFactory.sol"; import "./ClaimsManager.sol"; @@ -119,7 +120,7 @@ contract DelegateManager is RegistryContract { "Delegation not permitted for SP pending claim" ); address delegator = msg.sender; - Staking stakingContract = Staking( + ERCStakingInterface stakingContract = ERCStakingInterface( registry.getContract(stakingProxyOwnerKey) ); @@ -251,12 +252,10 @@ contract DelegateManager is RegistryContract { "Delegator must be staked for SP" ); - Staking stakingContract = Staking( - registry.getContract(stakingProxyOwnerKey) - ); - // Stake on behalf of target service provider - stakingContract.undelegateStakeFor( + ERCStakingInterface( + registry.getContract(stakingProxyOwnerKey) + ).undelegateStakeFor( serviceProvider, delegator, unstakeAmount, @@ -330,7 +329,7 @@ contract DelegateManager is RegistryContract { ); // Amount stored in staking contract for owner - uint totalBalanceInStaking = Staking( + uint totalBalanceInStaking = ERCStakingInterface( registry.getContract(stakingProxyOwnerKey) ).totalStakedFor(msg.sender); require(totalBalanceInStaking > 0, "Stake required for claim"); @@ -412,7 +411,7 @@ contract DelegateManager is RegistryContract { msg.sender == registry.getContract(governanceKey), "Slash only callable from governance contract" ); - Staking stakingContract = Staking( + ERCStakingInterface stakingContract = ERCStakingInterface( registry.getContract(stakingProxyOwnerKey) ); diff --git a/eth-contracts/contracts/service/ServiceProviderFactory.sol b/eth-contracts/contracts/service/ServiceProviderFactory.sol index b14cd575def..126f1a5f9ff 100644 --- a/eth-contracts/contracts/service/ServiceProviderFactory.sol +++ b/eth-contracts/contracts/service/ServiceProviderFactory.sol @@ -2,7 +2,7 @@ pragma solidity ^0.5.0; import "./registry/RegistryContract.sol"; import "./ServiceTypeManager.sol"; -import "../staking/ERCStaking.sol"; +import "../staking/ERCStakingInterface.sol"; import "./interface/registry/RegistryInterface.sol"; @@ -146,7 +146,7 @@ contract ServiceProviderFactory is RegistryContract { // Stake token amount from msg.sender if (_stakeAmount > 0) { - ERCStaking( + ERCStakingInterface( registry.getContract(stakingProxyOwnerKey) ).stakeFor(msg.sender, _stakeAmount, empty); } @@ -225,7 +225,7 @@ contract ServiceProviderFactory is RegistryContract { bool unstaked = false; // owned by the user if (spDetails[msg.sender].numberOfEndpoints == 1) { - ERCStaking stakingContract = ERCStaking( + ERCStakingInterface stakingContract = ERCStakingInterface( registry.getContract(stakingProxyOwnerKey) ); unstakeAmount = stakingContract.totalStakedFor(msg.sender); @@ -310,7 +310,7 @@ contract ServiceProviderFactory is RegistryContract { "Registered endpoint required to decrease stake" ); - ERCStaking stakingContract = ERCStaking( + ERCStakingInterface stakingContract = ERCStakingInterface( registry.getContract(stakingProxyOwnerKey) ); @@ -350,7 +350,7 @@ contract ServiceProviderFactory is RegistryContract { "Registered endpoint required to decrease stake" ); - ERCStaking stakingContract = ERCStaking( + ERCStakingInterface stakingContract = ERCStakingInterface( registry.getContract(stakingProxyOwnerKey) ); @@ -528,10 +528,9 @@ contract ServiceProviderFactory is RegistryContract { function validateAccountStakeBalance(address sp) external view returns (uint stakedForOwner) { - ERCStaking stakingContract = ERCStaking( + uint currentlyStakedForOwner = ERCStakingInterface( registry.getContract(stakingProxyOwnerKey) - ); - uint currentlyStakedForOwner = stakingContract.totalStakedFor(sp); + ).totalStakedFor(sp); require( currentlyStakedForOwner >= spDetails[sp].minAccountStake, @@ -552,11 +551,10 @@ contract ServiceProviderFactory is RegistryContract { * @notice Update service provider bound status */ function updateServiceProviderBoundStatus(address _serviceProvider) internal { - ERCStaking stakingContract = ERCStaking( - registry.getContract(stakingProxyOwnerKey) - ); // Validate bounds for total stake - uint totalSPStake = stakingContract.totalStakedFor(_serviceProvider); + uint totalSPStake = ERCStakingInterface( + registry.getContract(stakingProxyOwnerKey) + ).totalStakedFor(_serviceProvider); if (totalSPStake < spDetails[_serviceProvider].minAccountStake || totalSPStake > spDetails[_serviceProvider].maxAccountStake) { // Indicate this service provider is out of bounds diff --git a/eth-contracts/contracts/staking/ERCStaking.sol b/eth-contracts/contracts/staking/ERCStakingInterface.sol similarity index 68% rename from eth-contracts/contracts/staking/ERCStaking.sol rename to eth-contracts/contracts/staking/ERCStakingInterface.sol index 72153867244..401945cbc38 100644 --- a/eth-contracts/contracts/staking/ERCStaking.sol +++ b/eth-contracts/contracts/staking/ERCStakingInterface.sol @@ -4,22 +4,27 @@ pragma solidity ^0.5.0; // Modified interface for ERC900: https://eips.ethereum.org/EIPS/eip-900 // Eliminates direct stake operations -interface ERCStaking { +interface ERCStakingInterface { event Staked(address indexed user, uint256 amount, uint256 total, bytes data); event Unstaked(address indexed user, uint256 amount, uint256 total, bytes data); function stakeFor(address user, uint256 amount, bytes calldata data) external; function unstakeFor(address user, uint256 amount, bytes calldata data) external; + function stakeRewards(uint256 amount, address stakerAccount) external; + function delegateStakeFor(address accountAddress, address delegatorAddress, uint256 amount, bytes calldata data) external; + function undelegateStakeFor(address accountAddress, address delegatorAddress, uint256 amount, bytes calldata data) external; + function slash(uint256 amount, address slashAddress) external; + + function totalStakedFor(address addr) external view returns (uint256); function totalStaked() external view returns (uint256); function token() external view returns (address); function supportsHistory() external pure returns (bool); -} -interface ERCStakingHistory { function lastStakedFor(address addr) external view returns (uint256); function totalStakedForAt(address addr, uint256 blockNumber) external view returns (uint256); function totalStakedAt(uint256 blockNumber) external view returns (uint256); + function lastClaimedFor(address addr) external view returns (uint256); } diff --git a/eth-contracts/contracts/staking/Staking.sol b/eth-contracts/contracts/staking/Staking.sol index bdec5c4a132..e6b51bc7cf5 100644 --- a/eth-contracts/contracts/staking/Staking.sol +++ b/eth-contracts/contracts/staking/Staking.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.0; -import "./ERCStaking.sol"; +import "./ERCStakingInterface.sol"; import "./Checkpointing.sol"; import "../service/interface/registry/RegistryInterface.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol"; @@ -12,7 +12,7 @@ import "../service/registry/RegistryContract.sol"; /** NOTE - will call RegistryContract.constructor, which calls Ownable constructor */ -contract Staking is RegistryContract, ERCStaking, ERCStakingHistory, IsContract { +contract Staking is RegistryContract, ERCStakingInterface, IsContract { using SafeMath for uint256; using Checkpointing for Checkpointing.History; using SafeERC20 for ERC20; From 11a298cdbce618fe6907becb67095dc1b57c9ace Mon Sep 17 00:00:00 2001 From: Hareesh Nagaraj Date: Fri, 1 May 2020 16:39:55 -0400 Subject: [PATCH 4/6] Remove import --- eth-contracts/contracts/service/DelegateManager.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/eth-contracts/contracts/service/DelegateManager.sol b/eth-contracts/contracts/service/DelegateManager.sol index 89a0f682017..07c6be2915c 100644 --- a/eth-contracts/contracts/service/DelegateManager.sol +++ b/eth-contracts/contracts/service/DelegateManager.sol @@ -5,7 +5,6 @@ import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol import "./registry/RegistryContract.sol"; import "./interface/registry/RegistryInterface.sol"; -import "../staking/Staking.sol"; import "../staking/ERCStakingInterface.sol"; import "./ServiceProviderFactory.sol"; import "./ClaimsManager.sol"; From 2f820184c845147e26005e24fbcec7948c6badb9 Mon Sep 17 00:00:00 2001 From: Hareesh Nagaraj Date: Fri, 1 May 2020 17:46:02 -0400 Subject: [PATCH 5/6] Adding solcover.js --- eth-contracts/.solcover.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 eth-contracts/.solcover.js diff --git a/eth-contracts/.solcover.js b/eth-contracts/.solcover.js new file mode 100644 index 00000000000..a0621fcd962 --- /dev/null +++ b/eth-contracts/.solcover.js @@ -0,0 +1,5 @@ +module.exports = { + providerOptions: { + 'total_accounts': 20 + } +} From 09b87b4dca772c5c92f07feac0966d037754c6a5 Mon Sep 17 00:00:00 2001 From: Hareesh Nagaraj Date: Fri, 1 May 2020 17:51:33 -0400 Subject: [PATCH 6/6] interface rename, gitignore, governance interface consumption --- eth-contracts/.gitignore | 5 ++++- eth-contracts/contracts/Governance.sol | 10 +++++----- eth-contracts/contracts/service/ClaimsManager.sol | 8 ++++---- .../contracts/service/DelegateManager.sol | 10 +++++----- .../contracts/service/ServiceProviderFactory.sol | 14 +++++++------- eth-contracts/contracts/staking/Staking.sol | 4 ++-- ...RCStakingInterface.sol => StakingInterface.sol} | 2 +- 7 files changed, 28 insertions(+), 25 deletions(-) rename eth-contracts/contracts/staking/{ERCStakingInterface.sol => StakingInterface.sol} (98%) diff --git a/eth-contracts/.gitignore b/eth-contracts/.gitignore index 54cf6273cf8..c1b943b1259 100644 --- a/eth-contracts/.gitignore +++ b/eth-contracts/.gitignore @@ -5,4 +5,7 @@ .npmrc ganache_log.txt node_modules/ -build/ \ No newline at end of file +build/ +coverage/ +coverage.json +coverage.zip diff --git a/eth-contracts/contracts/Governance.sol b/eth-contracts/contracts/Governance.sol index a1469e9e768..24020253c3e 100644 --- a/eth-contracts/contracts/Governance.sol +++ b/eth-contracts/contracts/Governance.sol @@ -1,7 +1,7 @@ pragma solidity ^0.5.0; import "./service/registry/RegistryContract.sol"; -import "./staking/Staking.sol"; +import "./staking/StakingInterface.sol"; import "./service/interface/registry/RegistryInterface.sol"; @@ -102,7 +102,7 @@ contract Governance is RegistryContract { address proposer = msg.sender; // Require proposer is active Staker - Staking stakingContract = Staking(registry.getContract(stakingProxyOwnerKey)); + StakingInterface stakingContract = StakingInterface(registry.getContract(stakingProxyOwnerKey)); require( stakingContract.totalStakedFor(proposer) > 0, "Proposer must be active staker with non-zero stake." @@ -158,7 +158,7 @@ contract Governance is RegistryContract { ); // Require voter is active Staker + get voterStake. - Staking stakingContract = Staking(registry.getContract(stakingProxyOwnerKey)); + StakingInterface stakingContract = StakingInterface(registry.getContract(stakingProxyOwnerKey)); uint256 voterStake = stakingContract.totalStakedForAt( voter, proposals[_proposalId].startBlockNumber @@ -223,7 +223,7 @@ contract Governance is RegistryContract { ); // Require msg.sender is active Staker. - Staking stakingContract = Staking(registry.getContract(stakingProxyOwnerKey)); + StakingInterface stakingContract = StakingInterface(registry.getContract(stakingProxyOwnerKey)); require( stakingContract.totalStakedForAt( msg.sender, proposals[_proposalId].startBlockNumber @@ -372,4 +372,4 @@ contract Governance is RegistryContract { return returnData; } -} \ No newline at end of file +} diff --git a/eth-contracts/contracts/service/ClaimsManager.sol b/eth-contracts/contracts/service/ClaimsManager.sol index 44cb88f1ed8..8b7103e8ef0 100644 --- a/eth-contracts/contracts/service/ClaimsManager.sol +++ b/eth-contracts/contracts/service/ClaimsManager.sol @@ -1,5 +1,5 @@ pragma solidity ^0.5.0; -import "../staking/ERCStakingInterface.sol"; +import "../staking/StakingInterface.sol"; import "./registry/RegistryContract.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Mintable.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol"; @@ -107,7 +107,7 @@ contract ClaimsManager is RegistryContract { // Permissioned to stakers or contract deployer function initiateRound() external { requireIsInitialized(); - bool senderStaked = ERCStakingInterface( + bool senderStaked = StakingInterface( registry.getContract(stakingProxyOwnerKey) ).totalStakedFor(msg.sender) > 0; @@ -145,7 +145,7 @@ contract ClaimsManager is RegistryContract { ); address stakingAddress = registry.getContract(stakingProxyOwnerKey); - ERCStakingInterface stakingContract = ERCStakingInterface(stakingAddress); + StakingInterface stakingContract = StakingInterface(stakingAddress); // Prevent duplicate claim uint lastUserClaimBlock = stakingContract.lastClaimedFor(_claimer); require(lastUserClaimBlock <= fundBlock, "Claim already processed for user"); @@ -199,7 +199,7 @@ contract ClaimsManager is RegistryContract { } function claimPending(address _sp) external view returns (bool pending) { - uint lastClaimedForSP = ERCStakingInterface( + uint lastClaimedForSP = StakingInterface( registry.getContract(stakingProxyOwnerKey) ).lastClaimedFor(_sp); return (lastClaimedForSP < fundBlock); diff --git a/eth-contracts/contracts/service/DelegateManager.sol b/eth-contracts/contracts/service/DelegateManager.sol index 07c6be2915c..b121c65f842 100644 --- a/eth-contracts/contracts/service/DelegateManager.sol +++ b/eth-contracts/contracts/service/DelegateManager.sol @@ -5,7 +5,7 @@ import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol import "./registry/RegistryContract.sol"; import "./interface/registry/RegistryInterface.sol"; -import "../staking/ERCStakingInterface.sol"; +import "../staking/StakingInterface.sol"; import "./ServiceProviderFactory.sol"; import "./ClaimsManager.sol"; @@ -119,7 +119,7 @@ contract DelegateManager is RegistryContract { "Delegation not permitted for SP pending claim" ); address delegator = msg.sender; - ERCStakingInterface stakingContract = ERCStakingInterface( + StakingInterface stakingContract = StakingInterface( registry.getContract(stakingProxyOwnerKey) ); @@ -252,7 +252,7 @@ contract DelegateManager is RegistryContract { ); // Stake on behalf of target service provider - ERCStakingInterface( + StakingInterface( registry.getContract(stakingProxyOwnerKey) ).undelegateStakeFor( serviceProvider, @@ -328,7 +328,7 @@ contract DelegateManager is RegistryContract { ); // Amount stored in staking contract for owner - uint totalBalanceInStaking = ERCStakingInterface( + uint totalBalanceInStaking = StakingInterface( registry.getContract(stakingProxyOwnerKey) ).totalStakedFor(msg.sender); require(totalBalanceInStaking > 0, "Stake required for claim"); @@ -410,7 +410,7 @@ contract DelegateManager is RegistryContract { msg.sender == registry.getContract(governanceKey), "Slash only callable from governance contract" ); - ERCStakingInterface stakingContract = ERCStakingInterface( + StakingInterface stakingContract = StakingInterface( registry.getContract(stakingProxyOwnerKey) ); diff --git a/eth-contracts/contracts/service/ServiceProviderFactory.sol b/eth-contracts/contracts/service/ServiceProviderFactory.sol index 126f1a5f9ff..9c7c756aea8 100644 --- a/eth-contracts/contracts/service/ServiceProviderFactory.sol +++ b/eth-contracts/contracts/service/ServiceProviderFactory.sol @@ -2,7 +2,7 @@ pragma solidity ^0.5.0; import "./registry/RegistryContract.sol"; import "./ServiceTypeManager.sol"; -import "../staking/ERCStakingInterface.sol"; +import "../staking/StakingInterface.sol"; import "./interface/registry/RegistryInterface.sol"; @@ -146,7 +146,7 @@ contract ServiceProviderFactory is RegistryContract { // Stake token amount from msg.sender if (_stakeAmount > 0) { - ERCStakingInterface( + StakingInterface( registry.getContract(stakingProxyOwnerKey) ).stakeFor(msg.sender, _stakeAmount, empty); } @@ -225,7 +225,7 @@ contract ServiceProviderFactory is RegistryContract { bool unstaked = false; // owned by the user if (spDetails[msg.sender].numberOfEndpoints == 1) { - ERCStakingInterface stakingContract = ERCStakingInterface( + StakingInterface stakingContract = StakingInterface( registry.getContract(stakingProxyOwnerKey) ); unstakeAmount = stakingContract.totalStakedFor(msg.sender); @@ -310,7 +310,7 @@ contract ServiceProviderFactory is RegistryContract { "Registered endpoint required to decrease stake" ); - ERCStakingInterface stakingContract = ERCStakingInterface( + StakingInterface stakingContract = StakingInterface( registry.getContract(stakingProxyOwnerKey) ); @@ -350,7 +350,7 @@ contract ServiceProviderFactory is RegistryContract { "Registered endpoint required to decrease stake" ); - ERCStakingInterface stakingContract = ERCStakingInterface( + StakingInterface stakingContract = StakingInterface( registry.getContract(stakingProxyOwnerKey) ); @@ -528,7 +528,7 @@ contract ServiceProviderFactory is RegistryContract { function validateAccountStakeBalance(address sp) external view returns (uint stakedForOwner) { - uint currentlyStakedForOwner = ERCStakingInterface( + uint currentlyStakedForOwner = StakingInterface( registry.getContract(stakingProxyOwnerKey) ).totalStakedFor(sp); @@ -552,7 +552,7 @@ contract ServiceProviderFactory is RegistryContract { */ function updateServiceProviderBoundStatus(address _serviceProvider) internal { // Validate bounds for total stake - uint totalSPStake = ERCStakingInterface( + uint totalSPStake = StakingInterface( registry.getContract(stakingProxyOwnerKey) ).totalStakedFor(_serviceProvider); if (totalSPStake < spDetails[_serviceProvider].minAccountStake || diff --git a/eth-contracts/contracts/staking/Staking.sol b/eth-contracts/contracts/staking/Staking.sol index e6b51bc7cf5..1103f1e17f4 100644 --- a/eth-contracts/contracts/staking/Staking.sol +++ b/eth-contracts/contracts/staking/Staking.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.0; -import "./ERCStakingInterface.sol"; +import "./StakingInterface.sol"; import "./Checkpointing.sol"; import "../service/interface/registry/RegistryInterface.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol"; @@ -12,7 +12,7 @@ import "../service/registry/RegistryContract.sol"; /** NOTE - will call RegistryContract.constructor, which calls Ownable constructor */ -contract Staking is RegistryContract, ERCStakingInterface, IsContract { +contract Staking is RegistryContract, StakingInterface, IsContract { using SafeMath for uint256; using Checkpointing for Checkpointing.History; using SafeERC20 for ERC20; diff --git a/eth-contracts/contracts/staking/ERCStakingInterface.sol b/eth-contracts/contracts/staking/StakingInterface.sol similarity index 98% rename from eth-contracts/contracts/staking/ERCStakingInterface.sol rename to eth-contracts/contracts/staking/StakingInterface.sol index 401945cbc38..dcf83e7549c 100644 --- a/eth-contracts/contracts/staking/ERCStakingInterface.sol +++ b/eth-contracts/contracts/staking/StakingInterface.sol @@ -4,7 +4,7 @@ pragma solidity ^0.5.0; // Modified interface for ERC900: https://eips.ethereum.org/EIPS/eip-900 // Eliminates direct stake operations -interface ERCStakingInterface { +interface StakingInterface { event Staked(address indexed user, uint256 amount, uint256 total, bytes data); event Unstaked(address indexed user, uint256 amount, uint256 total, bytes data);