From 1977de79b9bc628232612ee65c0d0112ae9281ae Mon Sep 17 00:00:00 2001 From: Victoria Zotova Date: Fri, 10 Nov 2023 12:48:51 -0500 Subject: [PATCH 1/4] Adding interface for applications that use operator role and delay in authorization decrease --- .../staking/IApplicationWithDecreaseDelay.sol | 68 +++++++++++++++++++ .../staking/IApplicationWithOperator.sol | 42 ++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 contracts/staking/IApplicationWithDecreaseDelay.sol create mode 100644 contracts/staking/IApplicationWithOperator.sol diff --git a/contracts/staking/IApplicationWithDecreaseDelay.sol b/contracts/staking/IApplicationWithDecreaseDelay.sol new file mode 100644 index 00000000..d5d2ddf1 --- /dev/null +++ b/contracts/staking/IApplicationWithDecreaseDelay.sol @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +// ██████████████ ▐████▌ ██████████████ +// ██████████████ ▐████▌ ██████████████ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ +// ██████████████ ▐████▌ ██████████████ +// ██████████████ ▐████▌ ██████████████ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ + +pragma solidity ^0.8.9; + +import "./IApplication.sol"; + +/// @title Interface for Threshold Network applications with delay after decrease request +interface IApplicationWithDecreaseDelay is IApplication { + /// @notice Returns authorization-related parameters of the application. + /// @dev The minimum authorization is also returned by `minimumAuthorization()` + /// function, as a requirement of `IApplication` interface. + /// @return _minimumAuthorization The minimum authorization amount required + /// so that operator can participate in the application. + /// @return authorizationDecreaseDelay Delay in seconds that needs to pass + /// between the time authorization decrease is requested and the + /// time that request gets approved. Protects against free-riders + /// earning rewards and not being active in the network. + /// @return authorizationDecreaseChangePeriod Authorization decrease change + /// period in seconds. It is the time, before authorization decrease + /// delay end, during which the pending authorization decrease + /// request can be overwritten. + /// If set to 0, pending authorization decrease request can not be + /// overwritten until the entire `authorizationDecreaseDelay` ends. + /// If set to value equal `authorizationDecreaseDelay`, request can + /// always be overwritten. + function authorizationParameters() + external + view + returns ( + uint96 _minimumAuthorization, + uint64 authorizationDecreaseDelay, + uint64 authorizationDecreaseChangePeriod + ); + + /// @notice Returns the amount of stake that is pending authorization + /// decrease for the given staking provider. If no authorization + /// decrease has been requested, returns zero. + function pendingAuthorizationDecrease(address _stakingProvider) + external + view + returns (uint96); + + /// @notice Returns the remaining time in seconds that needs to pass before + /// the requested authorization decrease can be approved. + function remainingAuthorizationDecreaseDelay(address stakingProvider) + external + view + returns (uint64); + + /// @notice Approves the previously registered authorization decrease + /// request. Reverts if authorization decrease delay has not passed + /// yet or if the authorization decrease was not requested for the + /// given staking provider. + function approveAuthorizationDecrease(address stakingProvider) external; +} diff --git a/contracts/staking/IApplicationWithOperator.sol b/contracts/staking/IApplicationWithOperator.sol new file mode 100644 index 00000000..602c39b1 --- /dev/null +++ b/contracts/staking/IApplicationWithOperator.sol @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +// ██████████████ ▐████▌ ██████████████ +// ██████████████ ▐████▌ ██████████████ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ +// ██████████████ ▐████▌ ██████████████ +// ██████████████ ▐████▌ ██████████████ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ +// ▐████▌ ▐████▌ + +pragma solidity ^0.8.9; + +import "./IApplication.sol"; + +/// @title Interface for Threshold Network applications with operator role +interface IApplicationWithOperator is IApplication { + /// @notice Returns operator registered for the given staking provider. + function stakingProviderToOperator(address stakingProvider) + external + view + returns (address); + + /// @notice Used by staking provider to set operator address that will + /// operate a node. The operator addressmust be unique. + /// Reverts if the operator is already set for the staking provider + /// or if the operator address is already in use. + /// @dev Depending on application the given staking provider can set operator + /// address only one or multiple times. Besides that application can decide + /// if function reverts if there is a pending authorization decrease for + /// the staking provider. + function registerOperator(address operator) external; + + // TODO consider that? + // /// @notice Used by additional role (owner for example) to set operator address that will + // /// operate a node for the specified staking provider. + // function registerOperator(address stakingProvider, address operator) external; +} From 6b3f67423fd24e4e6d77014814b292325b5d2488 Mon Sep 17 00:00:00 2001 From: Victoria Date: Tue, 14 Nov 2023 16:13:06 +0200 Subject: [PATCH 2/4] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Núñez Co-authored-by: Derek Pierre --- contracts/staking/IApplicationWithDecreaseDelay.sol | 8 ++++---- contracts/staking/IApplicationWithOperator.sol | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/staking/IApplicationWithDecreaseDelay.sol b/contracts/staking/IApplicationWithDecreaseDelay.sol index d5d2ddf1..03ecc370 100644 --- a/contracts/staking/IApplicationWithDecreaseDelay.sol +++ b/contracts/staking/IApplicationWithDecreaseDelay.sol @@ -26,15 +26,15 @@ interface IApplicationWithDecreaseDelay is IApplication { /// so that operator can participate in the application. /// @return authorizationDecreaseDelay Delay in seconds that needs to pass /// between the time authorization decrease is requested and the - /// time that request gets approved. Protects against free-riders + /// time that request gets approved. Protects against participants /// earning rewards and not being active in the network. /// @return authorizationDecreaseChangePeriod Authorization decrease change - /// period in seconds. It is the time, before authorization decrease - /// delay end, during which the pending authorization decrease + /// period in seconds. It is the time window, before authorization decrease + /// delay ends, during which the pending authorization decrease /// request can be overwritten. /// If set to 0, pending authorization decrease request can not be /// overwritten until the entire `authorizationDecreaseDelay` ends. - /// If set to value equal `authorizationDecreaseDelay`, request can + /// If set to a value equal to `authorizationDecreaseDelay`, request can /// always be overwritten. function authorizationParameters() external diff --git a/contracts/staking/IApplicationWithOperator.sol b/contracts/staking/IApplicationWithOperator.sol index 602c39b1..6750194e 100644 --- a/contracts/staking/IApplicationWithOperator.sol +++ b/contracts/staking/IApplicationWithOperator.sol @@ -26,11 +26,11 @@ interface IApplicationWithOperator is IApplication { returns (address); /// @notice Used by staking provider to set operator address that will - /// operate a node. The operator addressmust be unique. + /// operate a node. The operator address must be unique. /// Reverts if the operator is already set for the staking provider /// or if the operator address is already in use. /// @dev Depending on application the given staking provider can set operator - /// address only one or multiple times. Besides that application can decide + /// address only once or multiple times. Besides that, application can decide /// if function reverts if there is a pending authorization decrease for /// the staking provider. function registerOperator(address operator) external; From c440eebc65b654322b49c5e3558f2f285ee1311c Mon Sep 17 00:00:00 2001 From: Victoria Zotova Date: Thu, 16 Nov 2023 13:56:16 -0500 Subject: [PATCH 3/4] IApplicationWithOperator: added method `operatorToStakingProvider` --- contracts/staking/IApplicationWithOperator.sol | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contracts/staking/IApplicationWithOperator.sol b/contracts/staking/IApplicationWithOperator.sol index 6750194e..d68724f0 100644 --- a/contracts/staking/IApplicationWithOperator.sol +++ b/contracts/staking/IApplicationWithOperator.sol @@ -25,6 +25,12 @@ interface IApplicationWithOperator is IApplication { view returns (address); + /// @notice Returns staking provider of the given operator. + function operatorToStakingProvider(address operator) + external + view + returns (address); + /// @notice Used by staking provider to set operator address that will /// operate a node. The operator address must be unique. /// Reverts if the operator is already set for the staking provider From 9b6155299c69b95486c619c365e0d478c0c84e6e Mon Sep 17 00:00:00 2001 From: Victoria Zotova Date: Mon, 20 Nov 2023 09:54:57 -0500 Subject: [PATCH 4/4] IApplicationWithOperator: removes optional `registerOperator` --- contracts/staking/IApplicationWithOperator.sol | 5 ----- 1 file changed, 5 deletions(-) diff --git a/contracts/staking/IApplicationWithOperator.sol b/contracts/staking/IApplicationWithOperator.sol index d68724f0..05879d21 100644 --- a/contracts/staking/IApplicationWithOperator.sol +++ b/contracts/staking/IApplicationWithOperator.sol @@ -40,9 +40,4 @@ interface IApplicationWithOperator is IApplication { /// if function reverts if there is a pending authorization decrease for /// the staking provider. function registerOperator(address operator) external; - - // TODO consider that? - // /// @notice Used by additional role (owner for example) to set operator address that will - // /// operate a node for the specified staking provider. - // function registerOperator(address stakingProvider, address operator) external; }