Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Updated holding references to staking contract
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nkuba committed Jun 22, 2020
1 parent fefc2a6 commit e699bbd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
32 changes: 20 additions & 12 deletions solidity/contracts/AbstractBonding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions solidity/contracts/ETHBonding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
);

Expand Down
9 changes: 5 additions & 4 deletions solidity/contracts/ETHStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions solidity/contracts/KeepBonding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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"
);
Expand Down

0 comments on commit e699bbd

Please sign in to comment.