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

Commit e699bbd

Browse files
committed
Updated holding references to staking contract
As TokenStaking contract has been refactored in threshold-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.
1 parent fefc2a6 commit e699bbd

4 files changed

Lines changed: 40 additions & 20 deletions

File tree

solidity/contracts/AbstractBonding.sol

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
pragma solidity 0.5.17;
1616

1717
import "@keep-network/keep-core/contracts/KeepRegistry.sol";
18-
import "@keep-network/keep-core/contracts/KeepStaking.sol";
18+
import "@keep-network/keep-core/contracts/Authorizations.sol";
19+
import "@keep-network/keep-core/contracts/StakeDelegatable.sol";
1920
import "@keep-network/sortition-pools/contracts/api/IBonding.sol";
2021
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
2122

@@ -28,8 +29,11 @@ contract AbstractBonding is IBonding {
2829
// Registry contract with a list of approved factories (operator contracts).
2930
KeepRegistry internal registry;
3031

31-
// Staking contract.
32-
KeepStaking internal staking;
32+
// Staking Authorizations contract.
33+
Authorizations internal authorizations;
34+
35+
// Stake Delegatable contract.
36+
StakeDelegatable internal stakeDelegatable;
3337

3438
// Unassigned value in wei deposited by operators.
3539
mapping(address => uint256) public unbondedValue;
@@ -71,12 +75,16 @@ contract AbstractBonding is IBonding {
7175

7276
/// @notice Initializes Keep Bonding contract.
7377
/// @param registryAddress Keep registry contract address.
74-
/// @param stakingContractAddress Keep staking contract address.
75-
constructor(address registryAddress, address stakingContractAddress)
76-
public
77-
{
78+
/// @param authorizationsAddress Staking Authorizations contract address.
79+
/// @param stakeDelegatableAddress Stake Delegatable contract address.
80+
constructor(
81+
address registryAddress,
82+
address authorizationsAddress,
83+
address stakeDelegatableAddress
84+
) public {
7885
registry = KeepRegistry(registryAddress);
79-
staking = KeepStaking(stakingContractAddress); // Rename to: Staking
86+
authorizations = Authorizations(authorizationsAddress);
87+
stakeDelegatable = StakeDelegatable(stakeDelegatableAddress);
8088
}
8189

8290
/// @notice Add the provided value to operator's pool available for bonding.
@@ -110,7 +118,7 @@ contract AbstractBonding is IBonding {
110118
// are no longer eligible. We cannot revert here.
111119
if (
112120
registry.isApprovedOperatorContract(bondCreator) &&
113-
staking.isAuthorizedForOperator(operator, bondCreator) &&
121+
authorizations.isAuthorizedForOperator(operator, bondCreator) &&
114122
hasSecondaryAuthorization(operator, authorizedSortitionPool)
115123
) {
116124
return unbondedValue[operator];
@@ -281,7 +289,7 @@ contract AbstractBonding is IBonding {
281289
address _poolAddress
282290
) public {
283291
require(
284-
staking.authorizerOf(_operator) == msg.sender,
292+
stakeDelegatable.authorizerOf(_operator) == msg.sender,
285293
"Not authorized"
286294
);
287295
authorizedPools[_operator][_poolAddress] = true;
@@ -298,7 +306,7 @@ contract AbstractBonding is IBonding {
298306
address _poolAddress
299307
) public {
300308
require(
301-
staking.authorizerOf(_operator) == msg.sender,
309+
stakeDelegatable.authorizerOf(_operator) == msg.sender,
302310
"Not authorized"
303311
);
304312
authorizedPools[_operator][_poolAddress] = false;
@@ -326,7 +334,7 @@ contract AbstractBonding is IBonding {
326334

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

329-
address beneficiary = staking.beneficiaryOf(operator);
337+
address beneficiary = stakeDelegatable.beneficiaryOf(operator);
330338
require(
331339
beneficiary != address(0),
332340
"Beneficiary not defined for the operator"

solidity/contracts/ETHBonding.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ contract ETHBonding is AbstractBonding {
2525
/// @param ethStakingAddress ETH Staking contract address.
2626
constructor(address registryAddress, address ethStakingAddress)
2727
public
28-
AbstractBonding(registryAddress, ethStakingAddress)
28+
AbstractBonding(registryAddress, ethStakingAddress, ethStakingAddress)
2929
{}
3030

3131
/// @notice Withdraws amount from operator's value available for bonding.
@@ -37,7 +37,8 @@ contract ETHBonding is AbstractBonding {
3737
/// @param operator Address of the operator.
3838
function withdraw(uint256 amount, address operator) public {
3939
require(
40-
msg.sender == operator || msg.sender == staking.ownerOf(operator),
40+
msg.sender == operator ||
41+
msg.sender == stakeDelegatable.ownerOf(operator),
4142
"Only operator or the owner is allowed to withdraw bond"
4243
);
4344

solidity/contracts/ETHStaking.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
pragma solidity 0.5.17;
1616

17+
import "@keep-network/keep-core/contracts/Authorizations.sol";
18+
import "@keep-network/keep-core/contracts/StakeDelegatable.sol";
1719
import "@keep-network/keep-core/contracts/KeepRegistry.sol";
18-
import "@keep-network/keep-core/contracts/KeepStaking.sol";
1920

2021
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
2122

@@ -24,10 +25,10 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol";
2425
/// @notice A staking contract for ETH staking. An owner of the ETH can delegate
2526
/// ETH as a stake to an operator. The value of ETH the owner is willing to stake
2627
/// should be deposited in `ETHBonding` contract for the given operator.
27-
contract ETHStaking is KeepStaking {
28-
constructor(address keepRegistryAddress)
28+
contract ETHStaking is Authorizations, StakeDelegatable {
29+
constructor(KeepRegistry keepRegistry)
2930
public
30-
KeepStaking(keepRegistryAddress)
31+
Authorizations(keepRegistry)
3132
{}
3233

3334
event Staked(

solidity/contracts/KeepBonding.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ contract KeepBonding is AbstractBonding {
3636
address registryAddress,
3737
address tokenStakingAddress,
3838
address tokenGrantAddress
39-
) public AbstractBonding(registryAddress, tokenStakingAddress) {
39+
)
40+
public
41+
AbstractBonding(
42+
registryAddress,
43+
tokenStakingAddress, // Authorizations
44+
tokenStakingAddress // StakeDelegatable
45+
)
46+
{
4047
tokenGrant = TokenGrant(tokenGrantAddress);
4148
}
4249

@@ -54,7 +61,10 @@ contract KeepBonding is AbstractBonding {
5461
function withdraw(uint256 amount, address operator) public {
5562
require(
5663
msg.sender == operator ||
57-
msg.sender.isTokenOwnerForOperator(operator, staking) ||
64+
msg.sender.isTokenOwnerForOperator(
65+
operator,
66+
stakeDelegatable
67+
) ||
5868
msg.sender.isGranteeForOperator(operator, tokenGrant),
5969
"Only operator or the owner is allowed to withdraw bond"
6070
);

0 commit comments

Comments
 (0)