Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIP-100 preparation #345

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 13 additions & 64 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 @@ -625,10 +595,19 @@ contract TACoApplication is
authorizedOverall -= effectiveDifference(_fromAmount, _toAmount, info);
}

info.authorized = _toAmount;
if (info.authorized < info.deauthorizing) {
info.deauthorizing = info.authorized;
uint96 decrease = info.authorized - _toAmount;
if (info.deauthorizing > decrease) {
info.deauthorizing -= decrease;
} else {
info.deauthorizing = 0;
info.endDeauthorization = 0;
}

info.authorized = _toAmount;

// if (info.authorized < info.deauthorizing) {
// info.deauthorizing = info.authorized;
// }
emit AuthorizationInvoluntaryDecreased(_stakingProvider, _fromAmount, _toAmount);

if (info.authorized == 0) {
Expand All @@ -654,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 @@ -727,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 @@ -1011,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
Loading
Loading