@web3dotorg/evm-slc-core-contracts 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/governance/NeutralsRegistry.sol +48 -21
- package/package.json +1 -1
@@ -63,7 +63,7 @@ contract NeutralsRegistry is INeutralsRegistry, ERC165, UUPSUpgradeable {
|
|
63
63
|
}
|
64
64
|
|
65
65
|
struct Delegation {
|
66
|
-
uint256
|
66
|
+
uint256 delegatedAmount;
|
67
67
|
WithdrawalAnnouncement withdrawal;
|
68
68
|
uint256 owedValue;
|
69
69
|
uint256 cumulativeSum;
|
@@ -254,6 +254,13 @@ contract NeutralsRegistry is INeutralsRegistry, ERC165, UUPSUpgradeable {
|
|
254
254
|
|
255
255
|
_checkDelegation(neutral_, amount_);
|
256
256
|
|
257
|
+
NeutralsRegistryStorage storage $ = _getNeutralsRegistryStorage();
|
258
|
+
|
259
|
+
if ($.delegations[msg.sender][neutral_].delegatedAmount == 0) {
|
260
|
+
$.neutralsPerDelegator[msg.sender].add(neutral_);
|
261
|
+
$.delegatorsPerNeutral[neutral_].add(msg.sender);
|
262
|
+
}
|
263
|
+
|
257
264
|
_addDelegationStake(msg.sender, neutral_, amount_);
|
258
265
|
|
259
266
|
_getNeutralsRegistryStorage().stakeToken.safeTransferFrom(
|
@@ -282,6 +289,11 @@ contract NeutralsRegistry is INeutralsRegistry, ERC165, UUPSUpgradeable {
|
|
282
289
|
|
283
290
|
delete $.delegations[neutral_][msg.sender].withdrawal;
|
284
291
|
|
292
|
+
if ($.delegations[msg.sender][neutral_].delegatedAmount == 0) {
|
293
|
+
$.neutralsPerDelegator[msg.sender].remove(neutral_);
|
294
|
+
$.delegatorsPerNeutral[neutral_].remove(msg.sender);
|
295
|
+
}
|
296
|
+
|
285
297
|
$.stakeToken.safeTransfer(msg.sender, amount_);
|
286
298
|
|
287
299
|
emit DelegationWithdrawn(msg.sender, neutral_, amount_);
|
@@ -657,7 +669,7 @@ contract NeutralsRegistry is INeutralsRegistry, ERC165, UUPSUpgradeable {
|
|
657
669
|
WithdrawalAnnouncement storage announcement = $
|
658
670
|
.delegations[msg.sender][neutral_].withdrawal;
|
659
671
|
|
660
|
-
uint256 delegationAmount_ = $.delegations[msg.sender][neutral_].
|
672
|
+
uint256 delegationAmount_ = $.delegations[msg.sender][neutral_].delegatedAmount;
|
661
673
|
|
662
674
|
if (amount_ > delegationAmount_)
|
663
675
|
revert InsufficientDelegationAmount(msg.sender, neutral_, amount_, delegationAmount_);
|
@@ -714,14 +726,39 @@ contract NeutralsRegistry is INeutralsRegistry, ERC165, UUPSUpgradeable {
|
|
714
726
|
}
|
715
727
|
|
716
728
|
/**
|
717
|
-
* @notice Get the available rewards for
|
729
|
+
* @notice Get the available rewards for the neutral
|
718
730
|
* @param neutral_ Address of the neutral
|
719
|
-
* @return Amount of
|
731
|
+
* @return Amount of rewards availible to claim
|
720
732
|
*/
|
721
|
-
function
|
733
|
+
function getNeutralRewards(address neutral_) public view returns (uint256) {
|
722
734
|
return _getNeutralsRegistryStorage().neutrals[neutral_].rewards;
|
723
735
|
}
|
724
736
|
|
737
|
+
/**
|
738
|
+
* @notice Get rewards for delegator per neutral
|
739
|
+
* @param delegator_ Address of the delegator
|
740
|
+
* @param neutral_ Address of the delegated neutral
|
741
|
+
* @return Amount of rewards availlible to claim
|
742
|
+
*/
|
743
|
+
function getDelegatorRewards(
|
744
|
+
address delegator_,
|
745
|
+
address neutral_
|
746
|
+
) public view returns (uint256) {
|
747
|
+
NeutralsRegistryStorage storage $ = _getNeutralsRegistryStorage();
|
748
|
+
Delegation storage delegation = $.delegations[delegator_][neutral_];
|
749
|
+
|
750
|
+
uint256 poolCumulativeSum_ = $.delegatorsRewardPools[neutral_].cumulativeSum;
|
751
|
+
uint256 delegatorShares_ = delegation.delegatedAmount;
|
752
|
+
|
753
|
+
return
|
754
|
+
delegation.owedValue +
|
755
|
+
Math.mulDiv(
|
756
|
+
delegatorShares_,
|
757
|
+
poolCumulativeSum_ - delegation.cumulativeSum,
|
758
|
+
PRECISION
|
759
|
+
);
|
760
|
+
}
|
761
|
+
|
725
762
|
/// @inheritdoc ERC165
|
726
763
|
function supportsInterface(
|
727
764
|
bytes4 interfaceId_
|
@@ -961,12 +998,7 @@ contract NeutralsRegistry is INeutralsRegistry, ERC165, UUPSUpgradeable {
|
|
961
998
|
NeutralsInfo storage neutralsInfo = $.neutrals[neutral_];
|
962
999
|
Delegation storage delegation = $.delegations[delegator_][neutral_];
|
963
1000
|
|
964
|
-
|
965
|
-
$.neutralsPerDelegator[delegator_].add(neutral_);
|
966
|
-
$.delegatorsPerNeutral[neutral_].add(delegator_);
|
967
|
-
}
|
968
|
-
|
969
|
-
delegation.delegationAmount += amount_;
|
1001
|
+
delegation.delegatedAmount += amount_;
|
970
1002
|
neutralsInfo.delegatedStake += amount_;
|
971
1003
|
|
972
1004
|
_recalculateNeutralWeight(neutral_);
|
@@ -983,14 +1015,9 @@ contract NeutralsRegistry is INeutralsRegistry, ERC165, UUPSUpgradeable {
|
|
983
1015
|
NeutralsInfo storage neutralsInfo = $.neutrals[neutral_];
|
984
1016
|
Delegation storage delegation = $.delegations[delegator_][neutral_];
|
985
1017
|
|
986
|
-
delegation.
|
1018
|
+
delegation.delegatedAmount -= amount_;
|
987
1019
|
neutralsInfo.delegatedStake -= amount_;
|
988
1020
|
|
989
|
-
if (delegation.delegationAmount == 0) {
|
990
|
-
$.neutralsPerDelegator[delegator_].remove(neutral_);
|
991
|
-
$.delegatorsPerNeutral[neutral_].remove(delegator_);
|
992
|
-
}
|
993
|
-
|
994
1021
|
_recalculateNeutralWeight(neutral_);
|
995
1022
|
}
|
996
1023
|
|
@@ -1027,13 +1054,13 @@ contract NeutralsRegistry is INeutralsRegistry, ERC165, UUPSUpgradeable {
|
|
1027
1054
|
DelegatorRewardPool storage rewardPool = $.delegatorsRewardPools[neutral_];
|
1028
1055
|
Delegation storage delegation = $.delegations[delegator_][neutral_];
|
1029
1056
|
|
1030
|
-
uint256 delegatedAmount_ = delegation.
|
1031
|
-
uint256
|
1032
|
-
uint256
|
1057
|
+
uint256 delegatedAmount_ = delegation.delegatedAmount;
|
1058
|
+
uint256 poolCumulativeSum_ = rewardPool.cumulativeSum;
|
1059
|
+
uint256 delegatorCumulativeSum_ = delegation.cumulativeSum;
|
1033
1060
|
|
1034
1061
|
delegation.owedValue += Math.mulDiv(
|
1035
1062
|
delegatedAmount_,
|
1036
|
-
|
1063
|
+
poolCumulativeSum_ - delegatorCumulativeSum_,
|
1037
1064
|
PRECISION
|
1038
1065
|
);
|
1039
1066
|
|