Skip to content

Commit

Permalink
Removes commitment lock
Browse files Browse the repository at this point in the history
  • Loading branch information
vzotova committed Feb 11, 2025
1 parent 399729c commit 57deb75
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 210 deletions.
62 changes: 1 addition & 61 deletions contracts/contracts/TACoApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,6 @@ contract TACoApplication is
uint256 startTimestamp
);

/**
* @notice Signals that a staking provider made a commitment
* @param stakingProvider Staking provider address
* @param endCommitment End of commitment
*/
event CommitmentMade(address indexed stakingProvider, uint256 endCommitment);

/**
* @notice Signals that manual child synchronization was called
* @param stakingProvider Staking provider address
Expand Down Expand Up @@ -190,7 +183,7 @@ contract TACoApplication is
uint64 endDeauthorization;
uint96 tReward;
uint160 rewardPerTokenPaid;
uint64 endCommitment;
uint64 legacyEndCommitment;
uint256 stub;
uint192 penaltyPercent;
uint64 endPenalty;
Expand All @@ -208,12 +201,6 @@ contract TACoApplication is
uint256 public immutable penaltyDuration;
uint192 public immutable penaltyIncrement;

uint64 public immutable commitmentDurationOption1;
uint64 public immutable commitmentDurationOption2;
uint64 public immutable commitmentDurationOption3;
uint64 public immutable commitmentDurationOption4;
uint64 public immutable commitmentDeadline;

IStaking public immutable tStaking;
IERC20 public immutable token;

Expand Down Expand Up @@ -241,8 +228,6 @@ contract TACoApplication is
* @param _minOperatorSeconds Min amount of seconds while an operator can't be changed
* @param _rewardDuration Duration of one reward cycle in seconds
* @param _deauthorizationDuration Duration of decreasing authorization in seconds
* @param _commitmentDurationOptions Options for commitment duration
* @param _commitmentDeadline Last date to make a commitment
* @param _penaltyDefault Default penalty percentage (as a value out of 10000)
* @param _penaltyDuration Duration of penalty
* @param _penaltyIncrement Increment of penalty if violation occurs during an existing penalty period
Expand All @@ -254,8 +239,6 @@ contract TACoApplication is
uint256 _minOperatorSeconds,
uint256 _rewardDuration,
uint256 _deauthorizationDuration,
uint64[] memory _commitmentDurationOptions,
uint64 _commitmentDeadline,
uint192 _penaltyDefault,
uint256 _penaltyDuration,
uint192 _penaltyIncrement
Expand All @@ -265,8 +248,6 @@ contract TACoApplication is
_rewardDuration != 0 &&
_tStaking.authorizedStake(address(this), address(this)) == 0 &&
totalSupply > 0 &&
_commitmentDurationOptions.length >= 1 &&
_commitmentDurationOptions.length <= 4 &&
_penaltyDefault > 0 &&
_penaltyDefault <= PENALTY_BASE &&
_penaltyDuration > 0 &&
Expand All @@ -286,17 +267,6 @@ contract TACoApplication is
token = _token;
tStaking = _tStaking;
minOperatorSeconds = _minOperatorSeconds;
commitmentDurationOption1 = _commitmentDurationOptions[0];
commitmentDurationOption2 = _commitmentDurationOptions.length >= 2
? _commitmentDurationOptions[1]
: 0;
commitmentDurationOption3 = _commitmentDurationOptions.length >= 3
? _commitmentDurationOptions[2]
: 0;
commitmentDurationOption4 = _commitmentDurationOptions.length >= 4
? _commitmentDurationOptions[3]
: 0;
commitmentDeadline = _commitmentDeadline;
penaltyDefault = _penaltyDefault;
penaltyDuration = _penaltyDuration;
penaltyIncrement = _penaltyIncrement;
Expand Down Expand Up @@ -663,10 +633,6 @@ contract TACoApplication is
_toAmount == 0 || _toAmount >= minimumAuthorization,
"Resulting authorization will be less than minimum"
);
require(
info.endCommitment <= block.timestamp,
"Can't request deauthorization before end of commitment"
);
if (info.operatorConfirmed) {
resynchronizeAuthorizedOverall(info, _fromAmount);
}
Expand Down Expand Up @@ -736,31 +702,6 @@ contract TACoApplication is
_updateAuthorization(_stakingProvider, info);
}

/**
* @notice Make a commitment to not request authorization decrease for specified duration
* @param _stakingProvider Staking provider address
* @param _commitmentDuration Duration of commitment
*/
function makeCommitment(
address _stakingProvider,
uint64 _commitmentDuration
) external onlyOwnerOrStakingProvider(_stakingProvider) {
require(block.timestamp < commitmentDeadline, "Commitment window closed");
require(
_commitmentDuration > 0 &&
(_commitmentDuration == commitmentDurationOption1 ||
_commitmentDuration == commitmentDurationOption2 ||
_commitmentDuration == commitmentDurationOption3 ||
_commitmentDuration == commitmentDurationOption4),
"Commitment duration must be equal to one of options"
);
StakingProviderInfo storage info = stakingProviderInfo[_stakingProvider];
require(info.endDeauthorization == 0, "Commitment can't be made during deauthorization");
require(info.endCommitment == 0, "Commitment already made");
info.endCommitment = uint64(block.timestamp) + _commitmentDuration;
emit CommitmentMade(_stakingProvider, info.endCommitment);
}

//-------------------------Main-------------------------
/**
* @notice Returns staking provider for specified operator
Expand Down Expand Up @@ -1020,7 +961,6 @@ contract TACoApplication is
info.operator = address(0);
info.operatorConfirmed = false;
info.endDeauthorization = 0;
info.endCommitment = 0;
childApplication.updateOperator(_stakingProvider, address(0));
}

Expand Down
7 changes: 0 additions & 7 deletions tests/application/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@

REWARD_DURATION = 60 * 60 * 24 * 7 # one week in seconds
DEAUTHORIZATION_DURATION = 60 * 60 * 24 * 60 # 60 days in seconds
COMMITMENT_DURATION_1 = 182 * 60 * 24 * 60 # 182 days in seconds
COMMITMENT_DURATION_2 = 2 * COMMITMENT_DURATION_1 # 365 days in seconds
COMMITMENT_DURATION_3 = 3 * COMMITMENT_DURATION_1 # 365 days in seconds
COMMITMENT_DEADLINE = 60 * 60 * 24 * 200 # 200 days after deploymwent

PENALTY_DEFAULT = 1000 # 10% penalty
PENALTY_INCREMENT = 2500 # 25% penalty increment
Expand Down Expand Up @@ -71,7 +67,6 @@ def encode_function_data(initializer=None, *args):

@pytest.fixture()
def taco_application(project, creator, token, threshold_staking, oz_dependency, chain):
now = chain.pending_timestamp
contract = creator.deploy(
project.TACoApplication,
token.address,
Expand All @@ -80,8 +75,6 @@ def taco_application(project, creator, token, threshold_staking, oz_dependency,
MIN_OPERATOR_SECONDS,
REWARD_DURATION,
DEAUTHORIZATION_DURATION,
[COMMITMENT_DURATION_1, COMMITMENT_DURATION_2, COMMITMENT_DURATION_3],
now + COMMITMENT_DEADLINE,
PENALTY_DEFAULT,
PENALTY_DURATION,
PENALTY_INCREMENT,
Expand Down
142 changes: 0 additions & 142 deletions tests/application/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
OPERATOR_CONFIRMED_SLOT = 1
AUTHORIZATION_SLOT = 3
END_DEAUTHORIZATION_SLOT = 5
END_COMMITMENT_SLOT = 8
MIN_AUTHORIZATION = Web3.to_wei(40_000, "ether")
DEAUTHORIZATION_DURATION = 60 * 60 * 24 * 60 # 60 days in seconds
PENALTY_DEFAULT = 1000 # 10% penalty
Expand Down Expand Up @@ -355,7 +354,6 @@ def test_involuntary_authorization_decrease(
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.authorizedOverall() == 0
assert taco_application.authorizedStake(staking_provider) == 0
assert child_application.stakingProviderInfo(staking_provider) == (0, 0, 0)
Expand Down Expand Up @@ -412,18 +410,6 @@ def test_involuntary_authorization_decrease(
assert child_application.stakingProviderInfo(staking_provider) == (authorization, 0, 0)
chain.pending_timestamp += PENALTY_DURATION

# Decrease everything again with previous commitment
commitment_duration = taco_application.commitmentDurationOption1()
taco_application.makeCommitment(staking_provider, commitment_duration, sender=staking_provider)
threshold_staking.involuntaryAuthorizationDecrease(
staking_provider, authorization, 0, sender=creator
)
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
assert taco_application.stakingProviderInfo(staking_provider)[END_COMMITMENT_SLOT] == 0


def test_authorization_decrease_request(
accounts, threshold_staking, taco_application, child_application, chain
Expand Down Expand Up @@ -568,25 +554,6 @@ def test_authorization_decrease_request(
assert taco_application.authorizedOverall() == value // 2 * 9 // 10
chain.pending_timestamp += PENALTY_DURATION

# Try to request decrease before ending of commitment
chain.pending_timestamp += deauthorization_duration
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)

# Commitment is still active
with ape.reverts("Can't request deauthorization before end of commitment"):
threshold_staking.authorizationDecreaseRequested(
staking_provider, value, value // 2, sender=creator
)
chain.pending_timestamp += commitment_duration

# Now decrease can be requested
threshold_staking.authorizationDecreaseRequested(
staking_provider, value, value // 2, sender=creator
)


def test_finish_authorization_decrease(
accounts, threshold_staking, taco_application, child_application, chain
Expand All @@ -602,9 +569,6 @@ def test_finish_authorization_decrease(

# Prepare staking providers
threshold_staking.authorizationIncreased(staking_provider, 0, value, sender=creator)
commitment_duration = taco_application.commitmentDurationOption1()
taco_application.makeCommitment(staking_provider, commitment_duration, sender=staking_provider)
chain.pending_timestamp += commitment_duration

# Can't approve decrease without request
with ape.reverts("There is no deauthorizing in process"):
Expand Down Expand Up @@ -662,7 +626,6 @@ def test_finish_authorization_decrease(
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.authorizedOverall() == 0
assert taco_application.authorizedStake(staking_provider) == new_value
assert child_application.stakingProviderInfo(staking_provider) == (new_value, 0, 0)
Expand Down Expand Up @@ -692,7 +655,6 @@ def test_finish_authorization_decrease(
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.stakingProviderToOperator(staking_provider) == staking_provider
assert taco_application.operatorToStakingProvider(staking_provider) == staking_provider
assert taco_application.authorizedOverall() == new_value
Expand Down Expand Up @@ -734,7 +696,6 @@ def test_finish_authorization_decrease(
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.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS
assert taco_application.operatorToStakingProvider(staking_provider) == ZERO_ADDRESS
assert taco_application.authorizedOverall() == 0
Expand Down Expand Up @@ -784,9 +745,6 @@ def test_resync(accounts, threshold_staking, taco_application, child_application

# Prepare staking providers
threshold_staking.authorizationIncreased(staking_provider, 0, value, sender=creator)
commitment_duration = taco_application.commitmentDurationOption1()
taco_application.makeCommitment(staking_provider, commitment_duration, sender=staking_provider)
chain.pending_timestamp += commitment_duration

# Nothing to resync
with ape.reverts():
Expand Down Expand Up @@ -828,7 +786,6 @@ def test_resync(accounts, threshold_staking, taco_application, child_application
tx = taco_application.resynchronizeAuthorization(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_COMMITMENT_SLOT] != 0
assert taco_application.authorizedOverall() == new_value
assert taco_application.stakingProviderToOperator(staking_provider) == staking_provider
assert taco_application.operatorToStakingProvider(staking_provider) == staking_provider
Expand Down Expand Up @@ -895,7 +852,6 @@ def test_resync(accounts, threshold_staking, taco_application, child_application
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.authorizedOverall() == 0
assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS
assert taco_application.operatorToStakingProvider(staking_provider) == ZERO_ADDRESS
Expand All @@ -915,104 +871,6 @@ def test_resync(accounts, threshold_staking, taco_application, child_application
]


def test_commitment(accounts, threshold_staking, taco_application, chain, child_application):
"""
Tests for authorization method: makeCommitment
"""

creator, staking_provider, another_staking_provider = accounts[0:3]
deauthorization_duration = DEAUTHORIZATION_DURATION
minimum_authorization = MIN_AUTHORIZATION
value = 2 * minimum_authorization
commitment_duration_1 = taco_application.commitmentDurationOption1()
commitment_duration_2 = taco_application.commitmentDurationOption2()
commitment_duration_3 = taco_application.commitmentDurationOption3()
commitment_deadline = taco_application.commitmentDeadline()

# Commitment can be made only for authorized staking provider
with ape.reverts("Not owner or provider"):
taco_application.makeCommitment(
staking_provider, commitment_duration_1, sender=staking_provider
)

# Prepare staking provider
threshold_staking.authorizationIncreased(staking_provider, 0, value, sender=creator)

# Begin deauthorization
threshold_staking.authorizationDecreaseRequested(
staking_provider, value, minimum_authorization, sender=creator
)

# Commitment can't be made during deauthorization
with ape.reverts("Commitment can't be made during deauthorization"):
taco_application.makeCommitment(
staking_provider, commitment_duration_3, sender=staking_provider
)

# Finish deauthorization
chain.pending_timestamp += deauthorization_duration
taco_application.approveAuthorizationDecrease(staking_provider, sender=creator)

# Commitment can be made only by staking provider
with ape.reverts("Not owner or provider"):
taco_application.makeCommitment(
staking_provider, commitment_duration_3, sender=another_staking_provider
)

# Commitment duration must be equal to one of options
with ape.reverts("Commitment duration must be equal to one of options"):
taco_application.makeCommitment(staking_provider, 0, sender=staking_provider)
with ape.reverts("Commitment duration must be equal to one of options"):
taco_application.makeCommitment(
staking_provider, commitment_duration_1 + 1, sender=staking_provider
)

# And make a commitment for shorter duration
tx = taco_application.makeCommitment(
staking_provider, commitment_duration_1, sender=staking_provider
)
timestamp = chain.pending_timestamp - 1
end_commitment = timestamp + commitment_duration_1
assert (
taco_application.stakingProviderInfo(staking_provider)[END_COMMITMENT_SLOT]
== end_commitment
)
assert tx.events == [
taco_application.CommitmentMade(
stakingProvider=staking_provider, endCommitment=end_commitment
)
]

# Commitment can't be made twice
with ape.reverts("Commitment already made"):
taco_application.makeCommitment(
staking_provider, commitment_duration_2, sender=staking_provider
)

# Another staking provider makes a commitment for longer period of time
threshold_staking.authorizationIncreased(another_staking_provider, 0, value, sender=creator)
tx = taco_application.makeCommitment(
another_staking_provider, commitment_duration_3, sender=another_staking_provider
)
timestamp = chain.pending_timestamp - 1
end_commitment = timestamp + commitment_duration_3
assert (
taco_application.stakingProviderInfo(another_staking_provider)[END_COMMITMENT_SLOT]
== end_commitment
)
assert tx.events == [
taco_application.CommitmentMade(
stakingProvider=another_staking_provider, endCommitment=end_commitment
)
]

# Wait until deadline
chain.pending_timestamp = commitment_deadline
threshold_staking.authorizationIncreased(creator, 0, value, sender=creator)
with ape.reverts("Commitment window closed"):
taco_application.makeCommitment(creator, commitment_duration_1, sender=creator)


def test_child_sync(accounts, threshold_staking, taco_application, child_application, chain):
"""
Tests for x-chain method: manualChildSynchronization
Expand Down

0 comments on commit 57deb75

Please sign in to comment.