From e699bbdc8837bcf660f014dc91766001b0bd076b Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Mon, 22 Jun 2020 15:58:25 +0200 Subject: [PATCH] Updated holding references to staking contract As TokenStaking contract has been refactored in keep-network/keep-core#1867 we can use Authorizations and StakeDelegatable contracts calls as these contracts define the functions we use in bonding. In this commit we use separately Authorizations and StakeDelegatable instead of TokenStaking to be more flexible and able to use common code from AbstractBonding for both KEEP token and ETH bonding. --- solidity/contracts/AbstractBonding.sol | 32 ++++++++++++++++---------- solidity/contracts/ETHBonding.sol | 5 ++-- solidity/contracts/ETHStaking.sol | 9 ++++---- solidity/contracts/KeepBonding.sol | 14 +++++++++-- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/solidity/contracts/AbstractBonding.sol b/solidity/contracts/AbstractBonding.sol index eec42d31a..ff215b114 100644 --- a/solidity/contracts/AbstractBonding.sol +++ b/solidity/contracts/AbstractBonding.sol @@ -15,7 +15,8 @@ pragma solidity 0.5.17; import "@keep-network/keep-core/contracts/KeepRegistry.sol"; -import "@keep-network/keep-core/contracts/KeepStaking.sol"; +import "@keep-network/keep-core/contracts/Authorizations.sol"; +import "@keep-network/keep-core/contracts/StakeDelegatable.sol"; import "@keep-network/sortition-pools/contracts/api/IBonding.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; @@ -28,8 +29,11 @@ contract AbstractBonding is IBonding { // Registry contract with a list of approved factories (operator contracts). KeepRegistry internal registry; - // Staking contract. - KeepStaking internal staking; + // Staking Authorizations contract. + Authorizations internal authorizations; + + // Stake Delegatable contract. + StakeDelegatable internal stakeDelegatable; // Unassigned value in wei deposited by operators. mapping(address => uint256) public unbondedValue; @@ -71,12 +75,16 @@ contract AbstractBonding is IBonding { /// @notice Initializes Keep Bonding contract. /// @param registryAddress Keep registry contract address. - /// @param stakingContractAddress Keep staking contract address. - constructor(address registryAddress, address stakingContractAddress) - public - { + /// @param authorizationsAddress Staking Authorizations contract address. + /// @param stakeDelegatableAddress Stake Delegatable contract address. + constructor( + address registryAddress, + address authorizationsAddress, + address stakeDelegatableAddress + ) public { registry = KeepRegistry(registryAddress); - staking = KeepStaking(stakingContractAddress); // Rename to: Staking + authorizations = Authorizations(authorizationsAddress); + stakeDelegatable = StakeDelegatable(stakeDelegatableAddress); } /// @notice Add the provided value to operator's pool available for bonding. @@ -110,7 +118,7 @@ contract AbstractBonding is IBonding { // are no longer eligible. We cannot revert here. if ( registry.isApprovedOperatorContract(bondCreator) && - staking.isAuthorizedForOperator(operator, bondCreator) && + authorizations.isAuthorizedForOperator(operator, bondCreator) && hasSecondaryAuthorization(operator, authorizedSortitionPool) ) { return unbondedValue[operator]; @@ -281,7 +289,7 @@ contract AbstractBonding is IBonding { address _poolAddress ) public { require( - staking.authorizerOf(_operator) == msg.sender, + stakeDelegatable.authorizerOf(_operator) == msg.sender, "Not authorized" ); authorizedPools[_operator][_poolAddress] = true; @@ -298,7 +306,7 @@ contract AbstractBonding is IBonding { address _poolAddress ) public { require( - staking.authorizerOf(_operator) == msg.sender, + stakeDelegatable.authorizerOf(_operator) == msg.sender, "Not authorized" ); authorizedPools[_operator][_poolAddress] = false; @@ -326,7 +334,7 @@ contract AbstractBonding is IBonding { unbondedValue[operator] = unbondedValue[operator].sub(amount); - address beneficiary = staking.beneficiaryOf(operator); + address beneficiary = stakeDelegatable.beneficiaryOf(operator); require( beneficiary != address(0), "Beneficiary not defined for the operator" diff --git a/solidity/contracts/ETHBonding.sol b/solidity/contracts/ETHBonding.sol index bb58ce307..99f6c6f2f 100644 --- a/solidity/contracts/ETHBonding.sol +++ b/solidity/contracts/ETHBonding.sol @@ -25,7 +25,7 @@ contract ETHBonding is AbstractBonding { /// @param ethStakingAddress ETH Staking contract address. constructor(address registryAddress, address ethStakingAddress) public - AbstractBonding(registryAddress, ethStakingAddress) + AbstractBonding(registryAddress, ethStakingAddress, ethStakingAddress) {} /// @notice Withdraws amount from operator's value available for bonding. @@ -37,7 +37,8 @@ contract ETHBonding is AbstractBonding { /// @param operator Address of the operator. function withdraw(uint256 amount, address operator) public { require( - msg.sender == operator || msg.sender == staking.ownerOf(operator), + msg.sender == operator || + msg.sender == stakeDelegatable.ownerOf(operator), "Only operator or the owner is allowed to withdraw bond" ); diff --git a/solidity/contracts/ETHStaking.sol b/solidity/contracts/ETHStaking.sol index 43572d994..2a556e38b 100644 --- a/solidity/contracts/ETHStaking.sol +++ b/solidity/contracts/ETHStaking.sol @@ -14,8 +14,9 @@ pragma solidity 0.5.17; +import "@keep-network/keep-core/contracts/Authorizations.sol"; +import "@keep-network/keep-core/contracts/StakeDelegatable.sol"; import "@keep-network/keep-core/contracts/KeepRegistry.sol"; -import "@keep-network/keep-core/contracts/KeepStaking.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; @@ -24,10 +25,10 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol"; /// @notice A staking contract for ETH staking. An owner of the ETH can delegate /// ETH as a stake to an operator. The value of ETH the owner is willing to stake /// should be deposited in `ETHBonding` contract for the given operator. -contract ETHStaking is KeepStaking { - constructor(address keepRegistryAddress) +contract ETHStaking is Authorizations, StakeDelegatable { + constructor(KeepRegistry keepRegistry) public - KeepStaking(keepRegistryAddress) + Authorizations(keepRegistry) {} event Staked( diff --git a/solidity/contracts/KeepBonding.sol b/solidity/contracts/KeepBonding.sol index 696e64c7e..a0b2dddec 100644 --- a/solidity/contracts/KeepBonding.sol +++ b/solidity/contracts/KeepBonding.sol @@ -36,7 +36,14 @@ contract KeepBonding is AbstractBonding { address registryAddress, address tokenStakingAddress, address tokenGrantAddress - ) public AbstractBonding(registryAddress, tokenStakingAddress) { + ) + public + AbstractBonding( + registryAddress, + tokenStakingAddress, // Authorizations + tokenStakingAddress // StakeDelegatable + ) + { tokenGrant = TokenGrant(tokenGrantAddress); } @@ -54,7 +61,10 @@ contract KeepBonding is AbstractBonding { function withdraw(uint256 amount, address operator) public { require( msg.sender == operator || - msg.sender.isTokenOwnerForOperator(operator, staking) || + msg.sender.isTokenOwnerForOperator( + operator, + stakeDelegatable + ) || msg.sender.isGranteeForOperator(operator, tokenGrant), "Only operator or the owner is allowed to withdraw bond" );