Skip to content

Commit

Permalink
Unifies some method names with other threshold projects
Browse files Browse the repository at this point in the history
  • Loading branch information
vzotova committed Nov 12, 2023
1 parent e0c38b8 commit 72c0a9c
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 74 deletions.
2 changes: 1 addition & 1 deletion contracts/contracts/Adjudicator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ contract Adjudicator {
SignatureVerifier.hashEIP191(stamp, bytes1(0x45)), // Currently, we use version E (0x45) of EIP191 signatures
_operatorIdentityEvidence
);
address stakingProvider = application.stakingProviderFromOperator(operator);
address stakingProvider = application.stakingProviderToOperator(operator);
require(stakingProvider != address(0), "Operator must be associated with a provider");

// 5. Check that staking provider can be slashed
Expand Down
33 changes: 26 additions & 7 deletions contracts/contracts/TACoApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";
import "@threshold/contracts/staking/IApplication.sol";
import "../threshold/IApplicationWithOperator.sol";
import "../threshold/IApplicationWithDecreaseDelay.sol";
import "@threshold/contracts/staking/IStaking.sol";
import "./coordination/ITACoRootToChild.sol";
import "./coordination/ITACoChildToRoot.sol";
Expand All @@ -16,7 +17,12 @@ import "./coordination/ITACoChildToRoot.sol";
* @title TACo Application
* @notice Contract distributes rewards for participating in app and slashes for violating rules
*/
contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
contract TACoApplication is
IApplicationWithDecreaseDelay,
IApplicationWithOperator,
ITACoChildToRoot,
OwnableUpgradeable
{
using SafeERC20 for IERC20;
using SafeCast for uint256;

Expand Down Expand Up @@ -306,6 +312,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
function authorizationParameters()
external
view
override
returns (
uint96 _minimumAuthorization,
uint64 authorizationDecreaseDelay,
Expand Down Expand Up @@ -529,7 +536,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
* @notice Approve request of decreasing authorization. Can be called by anyone
* @param _stakingProvider Address of staking provider
*/
function finishAuthorizationDecrease(
function approveAuthorizationDecrease(
address _stakingProvider
) external updateReward(_stakingProvider) {
StakingProviderInfo storage info = stakingProviderInfo[_stakingProvider];
Expand Down Expand Up @@ -611,7 +618,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
/**
* @notice Returns staking provider for specified operator
*/
function stakingProviderFromOperator(address _operator) external view returns (address) {
function stakingProviderToOperator(address _operator) external view returns (address) {
return _stakingProviderFromOperator[_operator];
}

Expand Down Expand Up @@ -643,7 +650,9 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
* decrease for the given staking provider. If no authorization
* decrease has been requested, returns zero.
*/
function pendingAuthorizationDecrease(address _stakingProvider) external view returns (uint96) {
function pendingAuthorizationDecrease(
address _stakingProvider
) external view override returns (uint96) {
return stakingProviderInfo[_stakingProvider].deauthorizing;
}

Expand All @@ -653,7 +662,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
*/
function remainingAuthorizationDecreaseDelay(
address _stakingProvider
) external view returns (uint64) {
) external view override returns (uint64) {
uint256 endDeauthorization = stakingProviderInfo[_stakingProvider].endDeauthorization;
if (endDeauthorization <= block.timestamp) {
return 0;
Expand Down Expand Up @@ -736,6 +745,16 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
return stakingProviders.length;
}

/**
* @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
* or if the operator address is already in use.
*/
function registerOperator(address _operator) external override {
bondOperator(msg.sender, _operator);
}

/**
* @notice Bond operator
* @param _stakingProvider Staking provider address
Expand All @@ -744,7 +763,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
function bondOperator(
address _stakingProvider,
address _operator
) external onlyOwnerOrStakingProvider(_stakingProvider) updateReward(_stakingProvider) {
) public onlyOwnerOrStakingProvider(_stakingProvider) updateReward(_stakingProvider) {
StakingProviderInfo storage info = stakingProviderInfo[_stakingProvider];
address previousOperator = info.operator;
require(
Expand Down
6 changes: 3 additions & 3 deletions contracts/contracts/coordination/Coordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable

function setProviderPublicKey(BLS12381.G2Point calldata _publicKey) external {
uint32 lastRitualId = uint32(rituals.length);
address stakingProvider = application.stakingProviderFromOperator(msg.sender);
address stakingProvider = application.stakingProviderToOperator(msg.sender);
require(stakingProvider != address(0), "Operator has no bond with staking provider");

ParticipantKey memory newRecord = ParticipantKey(lastRitualId, _publicKey);
Expand Down Expand Up @@ -288,7 +288,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable
"Not waiting for transcripts"
);

address provider = application.stakingProviderFromOperator(msg.sender);
address provider = application.stakingProviderToOperator(msg.sender);
Participant storage participant = getParticipantFromProvider(ritual, provider);

require(application.authorizedStake(provider) > 0, "Not enough authorization");
Expand Down Expand Up @@ -327,7 +327,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable
"Not waiting for aggregations"
);

address provider = application.stakingProviderFromOperator(msg.sender);
address provider = application.stakingProviderToOperator(msg.sender);
Participant storage participant = getParticipantFromProvider(ritual, provider);
require(application.authorizedStake(provider) > 0, "Not enough authorization");

Expand Down
8 changes: 4 additions & 4 deletions contracts/contracts/coordination/TACoChildApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia

mapping(address => StakingProviderInfo) public stakingProviderInfo;
address[] public stakingProviders;
mapping(address => address) public stakingProviderFromOperator;
mapping(address => address) public stakingProviderToOperator;

/**
* @dev Checks caller is root application
Expand Down Expand Up @@ -95,9 +95,9 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia

info.operator = operator;
// Update operator to provider mapping
stakingProviderFromOperator[oldOperator] = address(0);
stakingProviderToOperator[oldOperator] = address(0);
if (operator != address(0)) {
stakingProviderFromOperator[operator] = stakingProvider;
stakingProviderToOperator[operator] = stakingProvider;
}
info.operatorConfirmed = false;
// TODO placeholder to notify Coordinator
Expand All @@ -117,7 +117,7 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia

function confirmOperatorAddress(address _operator) external override {
require(msg.sender == coordinator, "Only Coordinator allowed to confirm operator");
address stakingProvider = stakingProviderFromOperator[_operator];
address stakingProvider = stakingProviderToOperator[_operator];
StakingProviderInfo storage info = stakingProviderInfo[stakingProvider];
require(
info.authorized >= minimumAuthorization,
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/AdjudicatorTestSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract TACoApplicationForAdjudicatorMock {
mapping(address => uint256) public rewardInfo;
mapping(address => address) internal _stakingProviderFromOperator;

function stakingProviderFromOperator(address _operator) public view returns (address) {
function stakingProviderToOperator(address _operator) public view returns (address) {
return _stakingProviderFromOperator[_operator];
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/test/CoordinatorTestSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import "../threshold/ITACoChildApplication.sol";
contract ChildApplicationForCoordinatorMock is ITACoChildApplication {
mapping(address => uint96) public authorizedStake;
mapping(address => address) public operatorFromStakingProvider;
mapping(address => address) public stakingProviderFromOperator;
mapping(address => address) public stakingProviderToOperator;
mapping(address => bool) public confirmations;

function updateOperator(address _stakingProvider, address _operator) external {
address oldOperator = operatorFromStakingProvider[_stakingProvider];
stakingProviderFromOperator[oldOperator] = address(0);
stakingProviderToOperator[oldOperator] = address(0);
operatorFromStakingProvider[_stakingProvider] = _operator;
stakingProviderFromOperator[_operator] = _stakingProvider;
stakingProviderToOperator[_operator] = _stakingProvider;
}

function updateAuthorization(address _stakingProvider, uint96 _amount) external {
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/TACoApplicationTestSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ contract ChildApplicationForTACoApplicationMock {

mapping(address => uint96) public authorizedStake;
mapping(address => address) public operatorFromStakingProvider;
mapping(address => address) public stakingProviderFromOperator;
mapping(address => address) public stakingProviderToOperator;

constructor(TACoApplication _rootApplication) {
rootApplication = _rootApplication;
}

function updateOperator(address _stakingProvider, address _operator) external {
address oldOperator = operatorFromStakingProvider[_stakingProvider];
stakingProviderFromOperator[oldOperator] = address(0);
stakingProviderToOperator[oldOperator] = address(0);
operatorFromStakingProvider[_stakingProvider] = _operator;
stakingProviderFromOperator[_operator] = _stakingProvider;
stakingProviderToOperator[_operator] = _stakingProvider;
}

function updateAuthorization(address _stakingProvider, uint96 _amount) external {
Expand Down
64 changes: 64 additions & 0 deletions contracts/threshold/IApplicationWithDecreaseDelay.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: GPL-3.0-or-later

// ██████████████ ▐████▌ ██████████████
// ██████████████ ▐████▌ ██████████████
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ██████████████ ▐████▌ ██████████████
// ██████████████ ▐████▌ ██████████████
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌

pragma solidity ^0.8.9;

import "@threshold/contracts/staking/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;
}
39 changes: 39 additions & 0 deletions contracts/threshold/IApplicationWithOperator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-3.0-or-later

// ██████████████ ▐████▌ ██████████████
// ██████████████ ▐████▌ ██████████████
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ██████████████ ▐████▌ ██████████████
// ██████████████ ▐████▌ ██████████████
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌

pragma solidity ^0.8.9;

import "@threshold/contracts/staking/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;
}
2 changes: 1 addition & 1 deletion contracts/threshold/ITACoChildApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
import "../contracts/coordination/ITACoChildToRoot.sol";

interface ITACoChildApplication is ITACoChildToRoot {
function stakingProviderFromOperator(address _operator) external view returns (address);
function stakingProviderToOperator(address _operator) external view returns (address);

function authorizedStake(address _stakingProvider) external view returns (uint96);

Expand Down
Loading

0 comments on commit 72c0a9c

Please sign in to comment.