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 Aug 11, 2020
1 parent 072ae63 commit b3931e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 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 @@ -27,8 +28,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 @@ -74,12 +78,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 @@ -122,7 +130,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 @@ -293,7 +301,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 @@ -310,7 +318,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 @@ -338,7 +346,7 @@ contract AbstractBonding is IBonding {

unbondedValue[operator] = unbondedValue[operator].sub(amount);

address beneficiary = staking.beneficiaryOf(operator);
address beneficiary = stakeDelegatable.beneficiaryOf(operator);

(bool success, ) = beneficiary.call.value(amount)("");
require(success, "Transfer failed");
Expand Down
14 changes: 12 additions & 2 deletions solidity/contracts/KeepBonding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 @@ -53,7 +60,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 b3931e4

Please sign in to comment.