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

Refactoring of _update on ERC4626StakeTokenUpgradeable #41

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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
30 changes: 10 additions & 20 deletions src/contracts/extension/ERC4626StakeTokenUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -192,31 +192,21 @@ abstract contract ERC4626StakeTokenUpgradeable is Initializable, ERC4626Upgradea
if (cooldownSnapshot.timestamp != 0) {
if (to == address(0)) {
// redeem
if (cooldownSnapshot.amount == value) {
delete $._stakerCooldown[from];

emit StakerCooldownDeleted(from);
} else {
uint224 amount = cooldownSnapshot.amount - value.toUint224();

$._stakerCooldown[from].amount = amount;

emit StakerCooldownAmountChanged(from, amount);
}
cooldownSnapshot.amount -= value.toUint224();
} else {
// transfer
uint224 balanceAfter = (balanceOfFrom - value).toUint224();

if (balanceAfter == 0) {
delete $._stakerCooldown[from];

emit StakerCooldownDeleted(from);
} else if (balanceAfter < cooldownSnapshot.amount) {
$._stakerCooldown[from].amount = balanceAfter;

emit StakerCooldownAmountChanged(from, balanceAfter);
if (balanceAfter <= cooldownSnapshot.amount) {
cooldownSnapshot.amount = balanceAfter;
}
}

if (cooldownSnapshot.amount == 0) {
cooldownSnapshot.timestamp = 0;
}
$._stakerCooldown[from] = cooldownSnapshot;

emit StakerCooldownAmountChanged(from, cooldownSnapshot.amount, cooldownSnapshot.timestamp);
}
}

Expand Down
Loading