Skip to content

Commit

Permalink
Merge branch 'sonic_sfc' into mike/sfc_merge
Browse files Browse the repository at this point in the history
# Conflicts:
#	contracts/sfc/SFC.sol
#	contracts/sfc/SFCBase.sol
#	contracts/sfc/SFCLib.sol
#	contracts/sfc/SFCState.sol
#	contracts/test/UnitTestSFC.sol
  • Loading branch information
Mike-CZ committed Oct 31, 2024
2 parents 998e2ad + 0c6a7de commit 3314c46
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 163 deletions.
12 changes: 1 addition & 11 deletions contracts/interfaces/INodeDriver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ interface INodeDriver {
uint256 deactivatedTime
) external;

function setGenesisDelegation(
address delegator,
uint256 toValidatorID,
uint256 stake,
uint256 lockedStake,
uint256 lockupFromEpoch,
uint256 lockupEndTime,
uint256 lockupDuration,
uint256 earlyUnlockPenalty,
uint256 rewards
) external;
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external;

function deactivateValidator(uint256 validatorID, uint256 status) external;

Expand Down
54 changes: 3 additions & 51 deletions contracts/interfaces/ISFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,9 @@ interface ISFC {
event Delegated(address indexed delegator, uint256 indexed toValidatorID, uint256 amount);
event Undelegated(address indexed delegator, uint256 indexed toValidatorID, uint256 indexed wrID, uint256 amount);
event Withdrawn(address indexed delegator, uint256 indexed toValidatorID, uint256 indexed wrID, uint256 amount);
event ClaimedRewards(
address indexed delegator,
uint256 indexed toValidatorID,
uint256 lockupExtraReward,
uint256 lockupBaseReward,
uint256 unlockedReward
);
event RestakedRewards(
address indexed delegator,
uint256 indexed toValidatorID,
uint256 lockupExtraReward,
uint256 lockupBaseReward,
uint256 unlockedReward
);
event ClaimedRewards(address indexed delegator, uint256 indexed toValidatorID, uint256 rewards);
event RestakedRewards(address indexed delegator, uint256 indexed toValidatorID, uint256 rewards);
event BurntFTM(uint256 amount);
event LockedUpStake(address indexed delegator, uint256 indexed validatorID, uint256 duration, uint256 amount);
event UnlockedStake(address indexed delegator, uint256 indexed validatorID, uint256 amount, uint256 penalty);
event UpdatedSlashingRefundRatio(uint256 indexed validatorID, uint256 refundRatio);
event RefundedSlashedLegacyDelegation(address indexed delegator, uint256 indexed validatorID, uint256 amount);

Expand All @@ -53,18 +39,8 @@ interface ISFC {
uint256 totalSupply
);

function getLockupInfo(
address,
uint256
) external view returns (uint256 lockedStake, uint256 fromEpoch, uint256 endTime, uint256 duration);

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

function getStashedLockupRewards(
address,
uint256
) external view returns (uint256 lockupExtraReward, uint256 lockupBaseReward, uint256 unlockedReward);

function getValidator(
uint256
)
Expand Down Expand Up @@ -106,8 +82,6 @@ interface ISFC {

function totalActiveStake() external view returns (uint256);

function totalSlashedStake() external view returns (uint256);

function totalStake() external view returns (uint256);

function totalSupply() external view returns (uint256);
Expand Down Expand Up @@ -142,8 +116,6 @@ interface ISFC {

function rewardsStash(address delegator, uint256 validatorID) external view returns (uint256);

function getLockedStake(address delegator, uint256 toValidatorID) external view returns (uint256);

function createValidator(bytes calldata pubkey) external payable;

function getSelfStake(uint256 validatorID) external view returns (uint256);
Expand Down Expand Up @@ -186,16 +158,6 @@ interface ISFC {

function sealEpochValidators(uint256[] calldata nextValidatorIDs) external;

function isLockedUp(address delegator, uint256 toValidatorID) external view returns (bool);

function getUnlockedStake(address delegator, uint256 toValidatorID) external view returns (uint256);

function lockStake(uint256 toValidatorID, uint256 lockupDuration, uint256 amount) external;

function relockStake(uint256 toValidatorID, uint256 lockupDuration, uint256 amount) external;

function unlockStake(uint256 toValidatorID, uint256 amount) external returns (uint256);

function initialize(
uint256 sealedEpoch,
uint256 _totalSupply,
Expand All @@ -215,17 +177,7 @@ interface ISFC {
uint256 deactivatedTime
) external;

function setGenesisDelegation(
address delegator,
uint256 toValidatorID,
uint256 stake,
uint256 lockedStake,
uint256 lockupFromEpoch,
uint256 lockupEndTime,
uint256 lockupDuration,
uint256 earlyUnlockPenalty,
uint256 rewards
) external;
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external;

function updateVoteBookAddress(address v) external;

Expand Down
36 changes: 0 additions & 36 deletions contracts/sfc/ConstantsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ contract ConstantsManager is Ownable {
uint256 public burntFeeShare;
// The percentage of fees to transfer to treasury address, e.g., 10%
uint256 public treasuryFeeShare;
// The ratio of the reward rate at base rate (no lock), e.g., 30%
uint256 public unlockedRewardRatio;
// The minimum duration of a stake/delegation lockup, e.g. 2 weeks
uint256 public minLockupDuration;
// The maximum duration of a stake/delegation lockup, e.g. 1 year
uint256 public maxLockupDuration;
// the number of epochs that undelegated stake is locked for
uint256 public withdrawalPeriodEpochs;
// the number of seconds that undelegated stake is locked for
Expand Down Expand Up @@ -87,36 +81,6 @@ contract ConstantsManager is Ownable {
treasuryFeeShare = v;
}

function updateUnlockedRewardRatio(uint256 v) external virtual onlyOwner {
if (v < (5 * Decimal.unit()) / 100) {
revert ValueTooSmall();
}
if (v > Decimal.unit() / 2) {
revert ValueTooLarge();
}
unlockedRewardRatio = v;
}

function updateMinLockupDuration(uint256 v) external virtual onlyOwner {
if (v < 86400) {
revert ValueTooSmall();
}
if (v > 86400 * 30) {
revert ValueTooLarge();
}
minLockupDuration = v;
}

function updateMaxLockupDuration(uint256 v) external virtual onlyOwner {
if (v < 86400 * 30) {
revert ValueTooSmall();
}
if (v > 86400 * 1460) {
revert ValueTooLarge();
}
maxLockupDuration = v;
}

function updateWithdrawalPeriodEpochs(uint256 v) external virtual onlyOwner {
if (v < 2) {
revert ValueTooSmall();
Expand Down
3 changes: 0 additions & 3 deletions contracts/sfc/NetworkInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ contract NetworkInitializer {
consts.updateValidatorCommission((15 * Decimal.unit()) / 100);
consts.updateBurntFeeShare((20 * Decimal.unit()) / 100);
consts.updateTreasuryFeeShare((10 * Decimal.unit()) / 100);
consts.updateUnlockedRewardRatio((30 * Decimal.unit()) / 100);
consts.updateMinLockupDuration(86400 * 14);
consts.updateMaxLockupDuration(86400 * 365);
consts.updateWithdrawalPeriodEpochs(3);
consts.updateWithdrawalPeriodTime(60 * 60 * 24 * 7);
consts.updateBaseRewardPerSecond(2668658453701531600);
Expand Down
24 changes: 2 additions & 22 deletions contracts/sfc/NodeDriver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,8 @@ contract NodeDriver is Initializable {
);
}

function setGenesisDelegation(
address delegator,
uint256 toValidatorID,
uint256 stake,
uint256 lockedStake,
uint256 lockupFromEpoch,
uint256 lockupEndTime,
uint256 lockupDuration,
uint256 earlyUnlockPenalty,
uint256 rewards
) external onlyNode {
backend.setGenesisDelegation(
delegator,
toValidatorID,
stake,
lockedStake,
lockupFromEpoch,
lockupEndTime,
lockupDuration,
earlyUnlockPenalty,
rewards
);
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external onlyNode {
backend.setGenesisDelegation(delegator, toValidatorID, stake);
}

function deactivateValidator(uint256 validatorID, uint256 status) external onlyNode {
Expand Down
24 changes: 2 additions & 22 deletions contracts/sfc/NodeDriverAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,8 @@ contract NodeDriverAuth is Initializable, Ownable {
);
}

function setGenesisDelegation(
address delegator,
uint256 toValidatorID,
uint256 stake,
uint256 lockedStake,
uint256 lockupFromEpoch,
uint256 lockupEndTime,
uint256 lockupDuration,
uint256 earlyUnlockPenalty,
uint256 rewards
) external onlyDriver {
sfc.setGenesisDelegation(
delegator,
toValidatorID,
stake,
lockedStake,
lockupFromEpoch,
lockupEndTime,
lockupDuration,
earlyUnlockPenalty,
rewards
);
function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake) external onlyDriver {
sfc.setGenesisDelegation(delegator, toValidatorID, stake);
}

function deactivateValidator(uint256 validatorID, uint256 status) external onlyDriver {
Expand Down
3 changes: 0 additions & 3 deletions contracts/sfc/Updater.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ contract Updater {
consts.updateValidatorCommission((15 * Decimal.unit()) / 100);
consts.updateBurntFeeShare((20 * Decimal.unit()) / 100);
consts.updateTreasuryFeeShare((10 * Decimal.unit()) / 100);
consts.updateUnlockedRewardRatio((30 * Decimal.unit()) / 100);
consts.updateMinLockupDuration(86400 * 14);
consts.updateMaxLockupDuration(86400 * 365);
consts.updateWithdrawalPeriodEpochs(3);
consts.updateWithdrawalPeriodTime(60 * 60 * 24 * 7);
consts.updateBaseRewardPerSecond(2668658453701531600);
Expand Down
15 changes: 0 additions & 15 deletions contracts/test/UnitTestSFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ contract UnitTestSFC is SFC {
}
return SFC.isNode(addr);
}

function highestLockupEpoch(address delegator, uint256 validatorID) external view returns (uint256) {
return _highestLockupEpoch(delegator, validatorID);
}

function _getAvgEpochStep(uint256) internal pure override returns (uint256) {
return 1;
}

function _getAvgUptime(uint256, uint256 duration, uint256) internal pure override returns (uint256) {
return duration;
}
}

contract UnitTestNetworkInitializer {
Expand All @@ -80,9 +68,6 @@ contract UnitTestNetworkInitializer {
consts.updateValidatorCommission((15 * Decimal.unit()) / 100);
consts.updateBurntFeeShare((20 * Decimal.unit()) / 100);
consts.updateTreasuryFeeShare((10 * Decimal.unit()) / 100);
consts.updateUnlockedRewardRatio((30 * Decimal.unit()) / 100);
consts.updateMinLockupDuration(86400 * 14);
consts.updateMaxLockupDuration(86400 * 365);
consts.updateWithdrawalPeriodEpochs(3);
consts.updateWithdrawalPeriodTime(60 * 60 * 24 * 7);
consts.updateBaseRewardPerSecond(6183414351851851852);
Expand Down

0 comments on commit 3314c46

Please sign in to comment.