diff --git a/contracts/contracts/Adjudicator.sol b/contracts/contracts/Adjudicator.sol index 0ecfeb44..ba71a8d3 100644 --- a/contracts/contracts/Adjudicator.sol +++ b/contracts/contracts/Adjudicator.sol @@ -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.operatorToStakingProvider(operator); require(stakingProvider != address(0), "Operator must be associated with a provider"); // 5. Check that staking provider can be slashed diff --git a/contracts/contracts/TACoApplication.sol b/contracts/contracts/TACoApplication.sol index 733f05dd..85828f9a 100644 --- a/contracts/contracts/TACoApplication.sol +++ b/contracts/contracts/TACoApplication.sol @@ -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"; @@ -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; @@ -312,6 +318,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable { function authorizationParameters() external view + override returns ( uint96 _minimumAuthorization, uint64 authorizationDecreaseDelay, @@ -535,7 +542,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]; @@ -618,16 +625,14 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable { /** * @notice Returns staking provider for specified operator */ - function stakingProviderFromOperator(address _operator) external view returns (address) { + function operatorToStakingProvider(address _operator) external view returns (address) { return _stakingProviderFromOperator[_operator]; } /** * @notice Returns operator for specified staking provider */ - function getOperatorFromStakingProvider( - address _stakingProvider - ) external view returns (address) { + function stakingProviderToOperator(address _stakingProvider) external view returns (address) { return stakingProviderInfo[_stakingProvider].operator; } @@ -650,7 +655,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; } @@ -660,7 +667,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; @@ -743,6 +750,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 @@ -751,7 +768,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( diff --git a/contracts/contracts/coordination/Coordinator.sol b/contracts/contracts/coordination/Coordinator.sol index dc5efd2a..7d699a35 100644 --- a/contracts/contracts/coordination/Coordinator.sol +++ b/contracts/contracts/coordination/Coordinator.sol @@ -176,7 +176,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.operatorToStakingProvider(msg.sender); require(stakingProvider != address(0), "Operator has no bond with staking provider"); ParticipantKey memory newRecord = ParticipantKey(lastRitualId, _publicKey); @@ -314,7 +314,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable "Not waiting for transcripts" ); - address provider = application.stakingProviderFromOperator(msg.sender); + address provider = application.operatorToStakingProvider(msg.sender); Participant storage participant = getParticipantFromProvider(ritual, provider); require(application.authorizedStake(provider) > 0, "Not enough authorization"); @@ -353,7 +353,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable "Not waiting for aggregations" ); - address provider = application.stakingProviderFromOperator(msg.sender); + address provider = application.operatorToStakingProvider(msg.sender); Participant storage participant = getParticipantFromProvider(ritual, provider); require(application.authorizedStake(provider) > 0, "Not enough authorization"); diff --git a/contracts/contracts/coordination/TACoChildApplication.sol b/contracts/contracts/coordination/TACoChildApplication.sol index 8d0d1095..4e7a0282 100644 --- a/contracts/contracts/coordination/TACoChildApplication.sol +++ b/contracts/contracts/coordination/TACoChildApplication.sol @@ -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 operatorToStakingProvider; /** * @dev Checks caller is root application @@ -95,9 +95,9 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia info.operator = operator; // Update operator to provider mapping - stakingProviderFromOperator[oldOperator] = address(0); + operatorToStakingProvider[oldOperator] = address(0); if (operator != address(0)) { - stakingProviderFromOperator[operator] = stakingProvider; + operatorToStakingProvider[operator] = stakingProvider; } info.operatorConfirmed = false; // TODO placeholder to notify Coordinator @@ -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 = operatorToStakingProvider[_operator]; StakingProviderInfo storage info = stakingProviderInfo[stakingProvider]; require( info.authorized >= minimumAuthorization, diff --git a/contracts/test/AdjudicatorTestSet.sol b/contracts/test/AdjudicatorTestSet.sol index 884f2dc6..c07b15bb 100644 --- a/contracts/test/AdjudicatorTestSet.sol +++ b/contracts/test/AdjudicatorTestSet.sol @@ -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 operatorToStakingProvider(address _operator) public view returns (address) { return _stakingProviderFromOperator[_operator]; } diff --git a/contracts/test/CoordinatorTestSet.sol b/contracts/test/CoordinatorTestSet.sol index 38d8707d..4968de07 100644 --- a/contracts/test/CoordinatorTestSet.sol +++ b/contracts/test/CoordinatorTestSet.sol @@ -12,14 +12,14 @@ contract ChildApplicationForCoordinatorMock is ITACoChildApplication { mapping(address => uint96) public authorizedStake; mapping(address => address) public operatorFromStakingProvider; - mapping(address => address) public stakingProviderFromOperator; + mapping(address => address) public operatorToStakingProvider; mapping(address => bool) public confirmations; function updateOperator(address _stakingProvider, address _operator) external { address oldOperator = operatorFromStakingProvider[_stakingProvider]; - stakingProviderFromOperator[oldOperator] = address(0); + operatorToStakingProvider[oldOperator] = address(0); operatorFromStakingProvider[_stakingProvider] = _operator; - stakingProviderFromOperator[_operator] = _stakingProvider; + operatorToStakingProvider[_operator] = _stakingProvider; } function updateAuthorization(address _stakingProvider, uint96 _amount) external { diff --git a/contracts/test/TACoApplicationTestSet.sol b/contracts/test/TACoApplicationTestSet.sol index ff95fc36..455b3c09 100644 --- a/contracts/test/TACoApplicationTestSet.sol +++ b/contracts/test/TACoApplicationTestSet.sol @@ -148,7 +148,7 @@ contract ChildApplicationForTACoApplicationMock { mapping(address => uint96) public authorizedStake; mapping(address => address) public operatorFromStakingProvider; - mapping(address => address) public stakingProviderFromOperator; + mapping(address => address) public operatorToStakingProvider; constructor(TACoApplication _rootApplication) { rootApplication = _rootApplication; @@ -156,9 +156,9 @@ contract ChildApplicationForTACoApplicationMock { function updateOperator(address _stakingProvider, address _operator) external { address oldOperator = operatorFromStakingProvider[_stakingProvider]; - stakingProviderFromOperator[oldOperator] = address(0); + operatorToStakingProvider[oldOperator] = address(0); operatorFromStakingProvider[_stakingProvider] = _operator; - stakingProviderFromOperator[_operator] = _stakingProvider; + operatorToStakingProvider[_operator] = _stakingProvider; } function updateAuthorization(address _stakingProvider, uint96 _amount) external { diff --git a/contracts/threshold/IApplicationWithDecreaseDelay.sol b/contracts/threshold/IApplicationWithDecreaseDelay.sol new file mode 100644 index 00000000..4a344cc9 --- /dev/null +++ b/contracts/threshold/IApplicationWithDecreaseDelay.sol @@ -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; +} diff --git a/contracts/threshold/IApplicationWithOperator.sol b/contracts/threshold/IApplicationWithOperator.sol new file mode 100644 index 00000000..a4cc0402 --- /dev/null +++ b/contracts/threshold/IApplicationWithOperator.sol @@ -0,0 +1,42 @@ +// 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 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 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; +} diff --git a/contracts/threshold/ITACoChildApplication.sol b/contracts/threshold/ITACoChildApplication.sol index f79fbff9..b823f796 100644 --- a/contracts/threshold/ITACoChildApplication.sol +++ b/contracts/threshold/ITACoChildApplication.sol @@ -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 operatorToStakingProvider(address _operator) external view returns (address); function authorizedStake(address _stakingProvider) external view returns (uint96); diff --git a/tests/application/test_authorization.py b/tests/application/test_authorization.py index 525f8897..25033b3e 100644 --- a/tests/application/test_authorization.py +++ b/tests/application/test_authorization.py @@ -228,8 +228,8 @@ def test_involuntary_authorization_decrease( assert child_application.authorizedStake(staking_provider) == 0 assert taco_application.isAuthorized(staking_provider) assert taco_application.isOperatorConfirmed(staking_provider) - assert taco_application.getOperatorFromStakingProvider(staking_provider) == staking_provider - assert taco_application.stakingProviderFromOperator(staking_provider) == staking_provider + assert taco_application.stakingProviderToOperator(staking_provider) == staking_provider + assert taco_application.operatorToStakingProvider(staking_provider) == staking_provider assert child_application.operatorFromStakingProvider(staking_provider) == staking_provider events = taco_application.AuthorizationInvoluntaryDecreased.from_receipt(tx) @@ -253,8 +253,8 @@ def test_involuntary_authorization_decrease( assert not taco_application.isAuthorized(staking_provider) assert not taco_application.isOperatorConfirmed(staking_provider) assert not taco_application.stakingProviderInfo(staking_provider)[OPERATOR_CONFIRMED_SLOT] - assert taco_application.getOperatorFromStakingProvider(staking_provider) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(staking_provider) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(staking_provider) == ZERO_ADDRESS assert child_application.operatorFromStakingProvider(staking_provider) == ZERO_ADDRESS events = taco_application.AuthorizationInvoluntaryDecreased.from_receipt(tx) @@ -293,7 +293,7 @@ def test_involuntary_authorization_decrease( threshold_staking.involuntaryAuthorizationDecrease( staking_provider, authorization, 0, sender=creator ) - assert taco_application.getOperatorFromStakingProvider(staking_provider) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS assert taco_application.stakingProviderInfo(staking_provider)[AUTHORIZATION_SLOT] == 0 assert taco_application.pendingAuthorizationDecrease(staking_provider) == 0 assert taco_application.stakingProviderInfo(staking_provider)[END_DEAUTHORIZATION_SLOT] == 0 @@ -411,7 +411,7 @@ def test_authorization_decrease_request( # Try to request decrease before ending of commitment chain.pending_timestamp += deauthorization_duration - taco_application.finishAuthorizationDecrease(staking_provider, sender=creator) + taco_application.approveAuthorizationDecrease(staking_provider, sender=creator) threshold_staking.authorizationIncreased(staking_provider, 0, value, sender=creator) commitment_duration = taco_application.commitmentDurationOption1() taco_application.makeCommitment(staking_provider, commitment_duration, sender=staking_provider) @@ -433,7 +433,7 @@ def test_finish_authorization_decrease( accounts, threshold_staking, taco_application, child_application, chain ): """ - Tests for authorization method: finishAuthorizationDecrease + Tests for authorization method: approveAuthorizationDecreas """ creator, staking_provider = accounts[0:2] @@ -449,7 +449,7 @@ def test_finish_authorization_decrease( # Can't approve decrease without request with ape.reverts(): - taco_application.finishAuthorizationDecrease(staking_provider, sender=creator) + taco_application.approveAuthorizationDecrease(staking_provider, sender=creator) new_value = 2 * minimum_authorization threshold_staking.authorizationDecreaseRequested( @@ -458,7 +458,7 @@ def test_finish_authorization_decrease( # Can't approve decrease before end timestamp with ape.reverts(): - taco_application.finishAuthorizationDecrease(staking_provider, sender=creator) + taco_application.approveAuthorizationDecrease(staking_provider, sender=creator) chain.pending_timestamp += deauthorization_duration // 4 remaining_duration = deauthorization_duration - deauthorization_duration // 4 @@ -470,7 +470,7 @@ def test_finish_authorization_decrease( # Wait some time chain.pending_timestamp += deauthorization_duration assert taco_application.remainingAuthorizationDecreaseDelay(staking_provider) == 0 - tx = taco_application.finishAuthorizationDecrease(staking_provider, sender=creator) + tx = taco_application.approveAuthorizationDecrease(staking_provider, sender=creator) assert taco_application.stakingProviderInfo(staking_provider)[AUTHORIZATION_SLOT] == new_value assert taco_application.pendingAuthorizationDecrease(staking_provider) == 0 assert taco_application.stakingProviderInfo(staking_provider)[END_DEAUTHORIZATION_SLOT] == 0 @@ -501,14 +501,14 @@ def test_finish_authorization_decrease( new_value = minimum_authorization // 2 threshold_staking.setDecreaseRequest(staking_provider, new_value, sender=creator) chain.pending_timestamp += deauthorization_duration - tx = taco_application.finishAuthorizationDecrease(staking_provider, sender=creator) + tx = taco_application.approveAuthorizationDecrease(staking_provider, sender=creator) assert taco_application.stakingProviderInfo(staking_provider)[AUTHORIZATION_SLOT] == new_value assert taco_application.pendingAuthorizationDecrease(staking_provider) == 0 assert taco_application.stakingProviderInfo(staking_provider)[END_DEAUTHORIZATION_SLOT] == 0 assert taco_application.stakingProviderInfo(staking_provider)[END_COMMITMENT_SLOT] != 0 - assert taco_application.getOperatorFromStakingProvider(staking_provider) == staking_provider - assert taco_application.stakingProviderFromOperator(staking_provider) == staking_provider + assert taco_application.stakingProviderToOperator(staking_provider) == staking_provider + assert taco_application.operatorToStakingProvider(staking_provider) == staking_provider assert taco_application.authorizedOverall() == new_value assert taco_application.authorizedStake(staking_provider) == new_value assert child_application.authorizedStake(staking_provider) == new_value @@ -530,14 +530,14 @@ def test_finish_authorization_decrease( value = new_value threshold_staking.authorizationDecreaseRequested(staking_provider, value, 0, sender=creator) chain.pending_timestamp += deauthorization_duration - tx = taco_application.finishAuthorizationDecrease(staking_provider, sender=creator) + tx = taco_application.approveAuthorizationDecrease(staking_provider, sender=creator) assert taco_application.stakingProviderInfo(staking_provider)[AUTHORIZATION_SLOT] == 0 assert taco_application.pendingAuthorizationDecrease(staking_provider) == 0 assert taco_application.stakingProviderInfo(staking_provider)[END_DEAUTHORIZATION_SLOT] == 0 assert taco_application.stakingProviderInfo(staking_provider)[END_COMMITMENT_SLOT] == 0 - assert taco_application.getOperatorFromStakingProvider(staking_provider) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(staking_provider) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(staking_provider) == ZERO_ADDRESS assert taco_application.authorizedOverall() == 0 assert taco_application.authorizedStake(staking_provider) == 0 assert child_application.authorizedStake(staking_provider) == 0 @@ -564,9 +564,9 @@ def test_finish_authorization_decrease( ) chain.pending_timestamp += deauthorization_duration threshold_staking.setDecreaseRequest(staking_provider, 0, sender=creator) - taco_application.finishAuthorizationDecrease(staking_provider, sender=creator) + taco_application.approveAuthorizationDecrease(staking_provider, sender=creator) assert taco_application.authorizedStake(staking_provider) == 0 - assert taco_application.getOperatorFromStakingProvider(staking_provider) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS def test_resync(accounts, threshold_staking, taco_application, child_application, chain): @@ -621,8 +621,8 @@ def test_resync(accounts, threshold_staking, taco_application, child_application assert taco_application.pendingAuthorizationDecrease(staking_provider) == 0 assert taco_application.stakingProviderInfo(staking_provider)[END_COMMITMENT_SLOT] != 0 assert taco_application.authorizedOverall() == new_value - assert taco_application.getOperatorFromStakingProvider(staking_provider) == staking_provider - assert taco_application.stakingProviderFromOperator(staking_provider) == staking_provider + assert taco_application.stakingProviderToOperator(staking_provider) == staking_provider + assert taco_application.operatorToStakingProvider(staking_provider) == staking_provider assert taco_application.authorizedOverall() == new_value assert taco_application.authorizedStake(staking_provider) == new_value assert child_application.authorizedStake(staking_provider) == new_value @@ -647,8 +647,8 @@ def test_resync(accounts, threshold_staking, taco_application, child_application assert taco_application.stakingProviderInfo(staking_provider)[AUTHORIZATION_SLOT] == new_value assert taco_application.pendingAuthorizationDecrease(staking_provider) == new_value assert taco_application.authorizedOverall() == new_value - assert taco_application.getOperatorFromStakingProvider(staking_provider) == staking_provider - assert taco_application.stakingProviderFromOperator(staking_provider) == staking_provider + assert taco_application.stakingProviderToOperator(staking_provider) == staking_provider + assert taco_application.operatorToStakingProvider(staking_provider) == staking_provider assert taco_application.authorizedOverall() == new_value assert taco_application.authorizedStake(staking_provider) == new_value assert child_application.authorizedStake(staking_provider) == 0 @@ -672,8 +672,8 @@ def test_resync(accounts, threshold_staking, taco_application, child_application assert taco_application.stakingProviderInfo(staking_provider)[END_DEAUTHORIZATION_SLOT] == 0 assert taco_application.stakingProviderInfo(staking_provider)[END_COMMITMENT_SLOT] == 0 assert taco_application.authorizedOverall() == 0 - assert taco_application.getOperatorFromStakingProvider(staking_provider) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(staking_provider) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(staking_provider) == ZERO_ADDRESS assert taco_application.authorizedOverall() == 0 assert taco_application.authorizedStake(staking_provider) == 0 assert child_application.authorizedStake(staking_provider) == 0 @@ -726,7 +726,7 @@ def test_commitment(accounts, threshold_staking, taco_application, chain, child_ # Finish deauthorization chain.pending_timestamp += deauthorization_duration - taco_application.finishAuthorizationDecrease(staking_provider, sender=creator) + taco_application.approveAuthorizationDecrease(staking_provider, sender=creator) # Commitment can be made only by staking provider with ape.reverts("Not owner or provider"): diff --git a/tests/application/test_operator.py b/tests/application/test_operator.py index 8045c870..11bc167a 100644 --- a/tests/application/test_operator.py +++ b/tests/application/test_operator.py @@ -56,14 +56,14 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl staking_provider_4, 0, min_authorization, sender=creator ) - assert taco_application.getOperatorFromStakingProvider(staking_provider_1) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(staking_provider_1) == ZERO_ADDRESS - assert taco_application.getOperatorFromStakingProvider(staking_provider_2) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(staking_provider_2) == ZERO_ADDRESS - assert taco_application.getOperatorFromStakingProvider(staking_provider_3) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(staking_provider_3) == ZERO_ADDRESS - assert taco_application.getOperatorFromStakingProvider(staking_provider_4) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(staking_provider_4) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider_1) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(staking_provider_1) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider_2) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(staking_provider_2) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider_3) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(staking_provider_3) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider_4) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(staking_provider_4) == ZERO_ADDRESS # Staking provider can't confirm operator address because there is no operator by default child_application.confirmOperatorAddress(staking_provider_1, sender=staking_provider_1) @@ -84,18 +84,22 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl taco_application.bondOperator(staking_provider_3, operator1, sender=beneficiary) with ape.reverts(): taco_application.bondOperator(staking_provider_3, operator1, sender=authorizer) + with ape.reverts(): + taco_application.registerOperator(operator1, sender=beneficiary) + with ape.reverts(): + taco_application.registerOperator(operator1, sender=authorizer) # Staking provider bonds operator and now operator can make a confirmation tx = taco_application.bondOperator(staking_provider_3, operator1, sender=owner3) timestamp = tx.timestamp - assert taco_application.getOperatorFromStakingProvider(staking_provider_3) == operator1 - assert taco_application.stakingProviderFromOperator(operator1) == staking_provider_3 + assert taco_application.stakingProviderToOperator(staking_provider_3) == operator1 + assert taco_application.operatorToStakingProvider(operator1) == staking_provider_3 assert not taco_application.stakingProviderInfo(staking_provider_3)[CONFIRMATION_SLOT] assert not taco_application.isOperatorConfirmed(operator1) assert taco_application.getStakingProvidersLength() == 1 assert taco_application.stakingProviders(0) == staking_provider_3 assert child_application.operatorFromStakingProvider(staking_provider_3) == operator1 - assert child_application.stakingProviderFromOperator(operator1) == staking_provider_3 + assert child_application.operatorToStakingProvider(operator1) == staking_provider_3 # No active stakingProviders before confirmation all_locked, staking_providers = taco_application.getActiveStakingProviders(0, 0) @@ -106,7 +110,7 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl assert taco_application.stakingProviderInfo(staking_provider_3)[CONFIRMATION_SLOT] assert taco_application.isOperatorConfirmed(operator1) assert child_application.operatorFromStakingProvider(staking_provider_3) == operator1 - assert child_application.stakingProviderFromOperator(operator1) == staking_provider_3 + assert child_application.operatorToStakingProvider(operator1) == staking_provider_3 events = taco_application.OperatorBonded.from_receipt(tx) assert events == [ @@ -147,15 +151,15 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl chain.pending_timestamp += min_operator_seconds tx = taco_application.bondOperator(staking_provider_3, ZERO_ADDRESS, sender=staking_provider_3) timestamp = tx.timestamp - assert taco_application.getOperatorFromStakingProvider(staking_provider_3) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(staking_provider_3) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(operator1) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider_3) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(staking_provider_3) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(operator1) == ZERO_ADDRESS assert not taco_application.stakingProviderInfo(staking_provider_3)[CONFIRMATION_SLOT] assert not taco_application.isOperatorConfirmed(operator1) assert taco_application.getStakingProvidersLength() == 1 assert taco_application.stakingProviders(0) == staking_provider_3 assert child_application.operatorFromStakingProvider(staking_provider_3) == ZERO_ADDRESS - assert child_application.stakingProviderFromOperator(operator1) == ZERO_ADDRESS + assert child_application.operatorToStakingProvider(operator1) == ZERO_ADDRESS # Resetting operator removes from active list before next confirmation all_locked, staking_providers = taco_application.getActiveStakingProviders(0, 0) @@ -173,16 +177,16 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl ] # The staking provider can bond now a new operator, without waiting additional time. - tx = taco_application.bondOperator(staking_provider_3, operator2, sender=staking_provider_3) + tx = taco_application.registerOperator(operator2, sender=staking_provider_3) timestamp = tx.timestamp - assert taco_application.getOperatorFromStakingProvider(staking_provider_3) == operator2 - assert taco_application.stakingProviderFromOperator(operator2) == staking_provider_3 + assert taco_application.stakingProviderToOperator(staking_provider_3) == operator2 + assert taco_application.operatorToStakingProvider(operator2) == staking_provider_3 assert not taco_application.stakingProviderInfo(staking_provider_3)[CONFIRMATION_SLOT] assert not taco_application.isOperatorConfirmed(operator2) assert taco_application.getStakingProvidersLength() == 1 assert taco_application.stakingProviders(0) == staking_provider_3 assert child_application.operatorFromStakingProvider(staking_provider_3) == operator2 - assert child_application.stakingProviderFromOperator(operator2) == staking_provider_3 + assert child_application.operatorToStakingProvider(operator2) == staking_provider_3 events = taco_application.OperatorBonded.from_receipt(tx) assert events == [ @@ -203,21 +207,21 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl assert taco_application.isOperatorConfirmed(operator2) assert taco_application.stakingProviderInfo(staking_provider_3)[CONFIRMATION_SLOT] assert child_application.operatorFromStakingProvider(staking_provider_3) == operator2 - assert child_application.stakingProviderFromOperator(operator2) == staking_provider_3 + assert child_application.operatorToStakingProvider(operator2) == staking_provider_3 # Another staking provider can bond a free operator assert taco_application.authorizedOverall() == min_authorization tx = taco_application.bondOperator(staking_provider_4, operator1, sender=staking_provider_4) timestamp = tx.timestamp - assert taco_application.getOperatorFromStakingProvider(staking_provider_4) == operator1 - assert taco_application.stakingProviderFromOperator(operator1) == staking_provider_4 + assert taco_application.stakingProviderToOperator(staking_provider_4) == operator1 + assert taco_application.operatorToStakingProvider(operator1) == staking_provider_4 assert not taco_application.isOperatorConfirmed(operator1) assert not taco_application.stakingProviderInfo(staking_provider_4)[CONFIRMATION_SLOT] assert taco_application.getStakingProvidersLength() == 2 assert taco_application.stakingProviders(1) == staking_provider_4 assert taco_application.authorizedOverall() == min_authorization assert child_application.operatorFromStakingProvider(staking_provider_4) == operator1 - assert child_application.stakingProviderFromOperator(operator1) == staking_provider_4 + assert child_application.operatorToStakingProvider(operator1) == staking_provider_4 events = taco_application.OperatorBonded.from_receipt(tx) assert events == [ @@ -241,14 +245,14 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl assert taco_application.stakingProviderInfo(staking_provider_4)[CONFIRMATION_SLOT] assert taco_application.authorizedOverall() == 2 * min_authorization assert child_application.operatorFromStakingProvider(staking_provider_4) == operator1 - assert child_application.stakingProviderFromOperator(operator1) == staking_provider_4 + assert child_application.operatorToStakingProvider(operator1) == staking_provider_4 chain.pending_timestamp += min_operator_seconds tx = taco_application.bondOperator(staking_provider_4, operator3, sender=staking_provider_4) timestamp = tx.timestamp - assert taco_application.getOperatorFromStakingProvider(staking_provider_4) == operator3 - assert taco_application.stakingProviderFromOperator(operator3) == staking_provider_4 - assert taco_application.stakingProviderFromOperator(operator1) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider_4) == operator3 + assert taco_application.operatorToStakingProvider(operator3) == staking_provider_4 + assert taco_application.operatorToStakingProvider(operator1) == ZERO_ADDRESS assert not taco_application.isOperatorConfirmed(operator3) assert not taco_application.isOperatorConfirmed(operator1) assert not taco_application.stakingProviderInfo(staking_provider_4)[CONFIRMATION_SLOT] @@ -256,8 +260,8 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl assert taco_application.stakingProviders(1) == staking_provider_4 assert taco_application.authorizedOverall() == min_authorization assert child_application.operatorFromStakingProvider(staking_provider_4) == operator3 - assert child_application.stakingProviderFromOperator(operator1) == ZERO_ADDRESS - assert child_application.stakingProviderFromOperator(operator3) == staking_provider_4 + assert child_application.operatorToStakingProvider(operator1) == ZERO_ADDRESS + assert child_application.operatorToStakingProvider(operator3) == staking_provider_4 # Resetting operator removes from active list before next confirmation all_locked, staking_providers = taco_application.getActiveStakingProviders(1, 0) @@ -277,8 +281,8 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl # The first operator is free and can deposit tokens and become a staking provider threshold_staking.setRoles(operator1, sender=creator) threshold_staking.authorizationIncreased(operator1, 0, min_authorization, sender=operator1) - assert taco_application.getOperatorFromStakingProvider(operator1) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(operator1) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(operator1) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(operator1) == ZERO_ADDRESS chain.pending_timestamp += min_operator_seconds @@ -292,8 +296,8 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl staking_provider_1, staking_provider_1, sender=staking_provider_1 ) timestamp = tx.timestamp - assert taco_application.getOperatorFromStakingProvider(staking_provider_1) == staking_provider_1 - assert taco_application.stakingProviderFromOperator(staking_provider_1) == staking_provider_1 + assert taco_application.stakingProviderToOperator(staking_provider_1) == staking_provider_1 + assert taco_application.operatorToStakingProvider(staking_provider_1) == staking_provider_1 assert taco_application.getStakingProvidersLength() == 3 assert taco_application.stakingProviders(2) == staking_provider_1 @@ -313,7 +317,7 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl ) child_application.confirmOperatorAddress(staking_provider_1, sender=staking_provider_1) assert child_application.operatorFromStakingProvider(staking_provider_1) == staking_provider_1 - assert child_application.stakingProviderFromOperator(staking_provider_1) == staking_provider_1 + assert child_application.operatorToStakingProvider(staking_provider_1) == staking_provider_1 # If stake will be less than minimum then provider is not active threshold_staking.authorizationIncreased( @@ -334,15 +338,15 @@ def test_bond_operator(accounts, threshold_staking, taco_application, child_appl assert len(staking_providers) == 0 # Unbond and rebond oeprator - taco_application.bondOperator(staking_provider_3, ZERO_ADDRESS, sender=staking_provider_3) - taco_application.bondOperator(staking_provider_3, operator2, sender=staking_provider_3) + taco_application.registerOperator(ZERO_ADDRESS, sender=staking_provider_3) + taco_application.registerOperator(operator2, sender=staking_provider_3) assert not taco_application.isOperatorConfirmed(operator2) # Operator can be unbonded before confirmation without restriction taco_application.bondOperator(staking_provider_3, ZERO_ADDRESS, sender=staking_provider_3) - assert taco_application.getOperatorFromStakingProvider(staking_provider_3) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(staking_provider_3) == ZERO_ADDRESS - assert taco_application.stakingProviderFromOperator(operator2) == ZERO_ADDRESS + assert taco_application.stakingProviderToOperator(staking_provider_3) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(staking_provider_3) == ZERO_ADDRESS + assert taco_application.operatorToStakingProvider(operator2) == ZERO_ADDRESS def test_confirm_address( diff --git a/tests/application/test_reward.py b/tests/application/test_reward.py index 90474d5c..7fb74199 100644 --- a/tests/application/test_reward.py +++ b/tests/application/test_reward.py @@ -238,7 +238,7 @@ def check_reward_with_confirmation(): # Finish decrease without confirmation chain.pending_timestamp += deauthorization_duration - taco_application.finishAuthorizationDecrease(staking_provider_2, sender=creator) + taco_application.approveAuthorizationDecrease(staking_provider_2, sender=creator) check_reward_no_confirmation() # Resync without confirmation @@ -279,7 +279,7 @@ def check_reward_with_confirmation(): # Finish decrease with confirmation chain.pending_timestamp += deauthorization_duration - taco_application.finishAuthorizationDecrease(staking_provider_2, sender=creator) + taco_application.approveAuthorizationDecrease(staking_provider_2, sender=creator) check_reward_with_confirmation() # Resync with confirmation diff --git a/tests/test_child_application.py b/tests/test_child_application.py index ebd0c128..fafcf503 100644 --- a/tests/test_child_application.py +++ b/tests/test_child_application.py @@ -75,7 +75,7 @@ def test_update_operator(accounts, root_application, child_application): # First bonding of operator tx = root_application.updateOperator(staking_provider_1, operator_1, sender=creator) - assert child_application.stakingProviderFromOperator(operator_1) == staking_provider_1 + assert child_application.operatorToStakingProvider(operator_1) == staking_provider_1 assert child_application.stakingProviderInfo(staking_provider_1)[OPERATOR_SLOT] == operator_1 assert not child_application.stakingProviderInfo(staking_provider_1)[CONFIRMATION_SLOT] assert child_application.getStakingProvidersLength() == 1 @@ -91,8 +91,8 @@ def test_update_operator(accounts, root_application, child_application): # Rebond operator tx = root_application.updateOperator(staking_provider_1, operator_2, sender=creator) - assert child_application.stakingProviderFromOperator(operator_2) == staking_provider_1 - assert child_application.stakingProviderFromOperator(operator_1) == ZERO_ADDRESS + assert child_application.operatorToStakingProvider(operator_2) == staking_provider_1 + assert child_application.operatorToStakingProvider(operator_1) == ZERO_ADDRESS assert child_application.stakingProviderInfo(staking_provider_1)[OPERATOR_SLOT] == operator_2 assert not child_application.stakingProviderInfo(operator_2)[CONFIRMATION_SLOT] assert not child_application.stakingProviderInfo(operator_1)[CONFIRMATION_SLOT] @@ -104,10 +104,10 @@ def test_update_operator(accounts, root_application, child_application): # Unbond operator tx = root_application.updateOperator(staking_provider_1, ZERO_ADDRESS, sender=creator) - assert child_application.stakingProviderFromOperator(operator_2) == ZERO_ADDRESS + assert child_application.operatorToStakingProvider(operator_2) == ZERO_ADDRESS assert child_application.stakingProviderInfo(staking_provider_1)[OPERATOR_SLOT] == ZERO_ADDRESS assert not child_application.stakingProviderInfo(operator_2)[CONFIRMATION_SLOT] - assert child_application.stakingProviderFromOperator(ZERO_ADDRESS) == ZERO_ADDRESS + assert child_application.operatorToStakingProvider(ZERO_ADDRESS) == ZERO_ADDRESS assert child_application.getStakingProvidersLength() == 1 assert tx.events == [ @@ -116,7 +116,7 @@ def test_update_operator(accounts, root_application, child_application): # Bonding from another address tx = root_application.updateOperator(staking_provider_2, operator_1, sender=creator) - assert child_application.stakingProviderFromOperator(operator_1) == staking_provider_2 + assert child_application.operatorToStakingProvider(operator_1) == staking_provider_2 assert child_application.stakingProviderInfo(staking_provider_2)[OPERATOR_SLOT] == operator_1 assert not child_application.stakingProviderInfo(operator_1)[CONFIRMATION_SLOT] assert child_application.getStakingProvidersLength() == 2 @@ -184,7 +184,7 @@ def test_confirm_address(accounts, root_application, child_application, coordina # First bonding of operator root_application.updateOperator(staking_provider, operator, sender=creator) - assert child_application.stakingProviderFromOperator(operator) == staking_provider + assert child_application.operatorToStakingProvider(operator) == staking_provider assert child_application.stakingProviderInfo(staking_provider)[OPERATOR_SLOT] == operator assert not child_application.stakingProviderInfo(staking_provider)[CONFIRMATION_SLOT] assert child_application.getStakingProvidersLength() == 1 @@ -242,7 +242,7 @@ def test_confirm_address(accounts, root_application, child_application, coordina # Changing operator resets confirmation root_application.updateOperator(other_staking_provider, other_operator, sender=creator) - assert child_application.stakingProviderFromOperator(other_operator) == other_staking_provider + assert child_application.operatorToStakingProvider(other_operator) == other_staking_provider assert ( child_application.stakingProviderInfo(other_staking_provider)[OPERATOR_SLOT] == other_operator