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

Remove StakeTokenizer #70

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 0 additions & 8 deletions contracts/sfc/SFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ contract SFC is SFCBase, Version {
getEpochSnapshot[sealedEpoch].endTime = _now();
}

function updateStakeTokenizerAddress(address addr) external onlyOwner {
stakeTokenizerAddress = addr;
}

function updateLibAddress(address v) external onlyOwner {
libAddress = v;
}
Expand All @@ -126,10 +122,6 @@ contract SFC is SFCBase, Version {
voteBookAddress = v;
}

function updateSFTMFinalizer(address v) external onlyOwner {
sftmFinalizer = v;
}

function migrateValidatorPubkeyUniquenessFlag(uint256 start, uint256 end) external {
for (uint256 vid = start; vid < end; vid++) {
bytes memory pubkey = getValidatorPubkey[vid];
Expand Down
8 changes: 0 additions & 8 deletions contracts/sfc/SFCI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ interface SFCI {

function slashingRefundRatio(uint256) external view returns (uint256);

function stakeTokenizerAddress() external view returns (address);

function stashedRewardsUntilEpoch(address, uint256) external view returns (uint256);

function totalActiveStake() external view returns (uint256);
Expand Down Expand Up @@ -171,8 +169,6 @@ interface SFCI {

function updateSlashingRefundRatio(uint256 validatorID, uint256 refundRatio) external;

function updateStakeTokenizerAddress(address addr) external;

function updateTreasuryAddress(address v) external;

function burnFTM(uint256 amount) external;
Expand Down Expand Up @@ -233,10 +229,6 @@ interface SFCI {

function voteBookAddress() external view returns (address);

function liquidateSFTM(address delegator, uint256 toValidatorID, uint256 amount) external;

function updateSFTMFinalizer(address v) external;

function updateValidatorPubkey(bytes calldata pubkey) external;

function migrateValidatorPubkeyUniquenessFlag(uint256 start, uint256 end) external;
Expand Down
43 changes: 0 additions & 43 deletions contracts/sfc/SFCLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.9;
import "../common/Decimal.sol";
import "./GasPriceConstants.sol";
import "./SFCBase.sol";
import "./StakeTokenizer.sol";
import "./NodeDriver.sol";

contract SFCLib is SFCBase {
Expand Down Expand Up @@ -229,7 +228,6 @@ contract SFCLib is SFCBase {

require(amount > 0, "zero amount");
require(amount <= getUnlockedStake(delegator, toValidatorID), "not enough unlocked stake");
require(_checkAllowedToWithdraw(delegator, toValidatorID), "outstanding sFTM balance");

require(getWithdrawalRequest[delegator][toValidatorID][wrID].amount == 0, "wrID already exists");

Expand All @@ -244,37 +242,6 @@ contract SFCLib is SFCBase {
emit Undelegated(delegator, toValidatorID, wrID, amount);
}

// liquidateSFTM is used for finalization of last fMint positions with outstanding sFTM balances
// it allows to undelegate without the unboding period, and also to unlock stake without a penalty.
// Such a simplification, which might be dangerous generally, is okay here because there's only a small amount
// of leftover sFTM
function liquidateSFTM(address delegator, uint256 toValidatorID, uint256 amount) external {
require(msg.sender == sftmFinalizer, "not sFTM finalizer");
_stashRewards(delegator, toValidatorID);

require(amount > 0, "zero amount");
StakeTokenizer(stakeTokenizerAddress).redeemSFTMFor(msg.sender, delegator, toValidatorID, amount);
require(amount <= getStake[delegator][toValidatorID], "not enough stake");
uint256 unlockedStake = getUnlockedStake(delegator, toValidatorID);
if (amount > unlockedStake) {
LockedDelegation storage ld = getLockupInfo[delegator][toValidatorID];
ld.lockedStake = ld.lockedStake - amount - unlockedStake;
emit UnlockedStake(delegator, toValidatorID, amount - unlockedStake, 0);
}

_rawUndelegate(delegator, toValidatorID, amount, false, true, false);

_syncValidator(toValidatorID, false);

emit Undelegated(delegator, toValidatorID, 0xffffffffff, amount);

// It's important that we transfer after erasing (protection against Re-Entrancy)
(bool sent, ) = msg.sender.call{value: amount}("");
require(sent, "Failed to send FTM");

emit Withdrawn(delegator, toValidatorID, 0xffffffffff, amount);
}

function isSlashed(uint256 validatorID) public view returns (bool) {
return getValidator[validatorID].status & CHEATER_MASK != 0;
}
Expand All @@ -298,7 +265,6 @@ contract SFCLib is SFCBase {
function _withdraw(address delegator, uint256 toValidatorID, uint256 wrID, address payable receiver) private {
WithdrawalRequest memory request = getWithdrawalRequest[delegator][toValidatorID][wrID];
require(request.epoch != 0, "request doesn't exist");
require(_checkAllowedToWithdraw(delegator, toValidatorID), "outstanding sFTM balance");

uint256 requestTime = request.time;
uint256 requestEpoch = request.epoch;
Expand Down Expand Up @@ -455,7 +421,6 @@ contract SFCLib is SFCBase {
}

function _claimRewards(address delegator, uint256 toValidatorID) internal returns (Rewards memory rewards) {
require(_checkAllowedToWithdraw(delegator, toValidatorID), "outstanding sFTM balance");
_stashRewards(delegator, toValidatorID);
rewards = _rewardsStash[delegator][toValidatorID];
uint256 totalReward = rewards.unlockedReward + rewards.lockupBaseReward + rewards.lockupExtraReward;
Expand Down Expand Up @@ -522,13 +487,6 @@ contract SFCLib is SFCBase {
epochEndTime(epoch) <= getLockupInfo[delegator][toValidatorID].endTime;
}

function _checkAllowedToWithdraw(address delegator, uint256 toValidatorID) internal view returns (bool) {
if (stakeTokenizerAddress == address(0)) {
return true;
}
return StakeTokenizer(stakeTokenizerAddress).allowedToWithdrawStake(delegator, toValidatorID);
}

function getUnlockedStake(address delegator, uint256 toValidatorID) public view returns (uint256) {
if (!isLockedUp(delegator, toValidatorID)) {
return getStake[delegator][toValidatorID];
Expand Down Expand Up @@ -653,7 +611,6 @@ contract SFCLib is SFCBase {
require(amount > 0, "zero amount");
require(isLockedUp(delegator, toValidatorID), "not locked up");
require(amount <= ld.lockedStake, "not enough locked stake");
require(_checkAllowedToWithdraw(delegator, toValidatorID), "outstanding sFTM balance");
require(!_redirected(delegator), "redirected");

_stashRewards(delegator, toValidatorID);
Expand Down
4 changes: 0 additions & 4 deletions contracts/sfc/SFCState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ contract SFCState is Initializable, Ownable {

mapping(uint256 => uint256) public slashingRefundRatio; // validator ID -> (slashing refund ratio)

address public stakeTokenizerAddress;

uint256 private erased3;
uint256 private erased4;
uint256 public minGasPrice;
Expand All @@ -102,8 +100,6 @@ contract SFCState is Initializable, Ownable {

address public voteBookAddress;

address internal sftmFinalizer;

struct Penalty {
uint256 amount;
uint256 end;
Expand Down
61 changes: 0 additions & 61 deletions contracts/sfc/StakeTokenizer.sol

This file was deleted.

4 changes: 0 additions & 4 deletions contracts/test/UnitTestSFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ interface SFCUnitTestI {

function slashingRefundRatio(uint256) external view returns (uint256);

function stakeTokenizerAddress() external view returns (address);

function stashedRewardsUntilEpoch(address, uint256) external view returns (uint256);

function targetGasPowerPerSecond() external view returns (uint256);
Expand Down Expand Up @@ -251,8 +249,6 @@ interface SFCUnitTestI {

function updateSlashingRefundRatio(uint256 validatorID, uint256 refundRatio) external;

function updateStakeTokenizerAddress(address addr) external;

function updateTreasuryAddress(address v) external;

function burnFTM(uint256 amount) external;
Expand Down
Loading