@@ -633,11 +633,13 @@ public InspireResultDto calculationUserIncentives(UserInspireCalculationDto dto)
633
633
String [] addressSplit = paramsConfig .FOUNDATION_ADDRESSES .split ("," );
634
634
List <String > foundationAddresses = Arrays .asList (addressSplit );
635
635
636
- Long stakeAmount = dto .getStakeAmount ();
636
+ Long nodeAddAmount = Optional .ofNullable (dto .getNodeAddAmount ()).orElse (0L );
637
+ Long stakeAmount = Optional .ofNullable (dto .getStakeAmount ()).orElse (0L );
637
638
String publicKey = dto .getPublicKey ();
638
- if (stakeAmount <= 0 ) {
639
+ if (nodeAddAmount <= 0 && stakeAmount <= 0 ) {
639
640
throw new ExplorerException (ErrorInfo .PARAM_ERROR );
640
641
}
642
+
641
643
Long oldCurrentStake = 0L ;
642
644
Long newCurrentStake = 0L ;
643
645
initSDK ();
@@ -654,6 +656,7 @@ public InspireResultDto calculationUserIncentives(UserInspireCalculationDto dto)
654
656
if (one .getPublicKey ().equals (publicKey )) {
655
657
oldCurrentStake = one .getCurrentStake ();
656
658
Long initPos = one .getInitPos ();
659
+ Long newInitPos = initPos + nodeAddAmount ;
657
660
Long totalPos = one .getTotalPos ();
658
661
Long maxAuthorize = one .getMaxAuthorize ();
659
662
Long allowMaxStake = maxAuthorize - totalPos ;
@@ -662,7 +665,8 @@ public InspireResultDto calculationUserIncentives(UserInspireCalculationDto dto)
662
665
stakeAmount = allowMaxStake ;
663
666
}
664
667
665
- newCurrentStake = initPos + newTotalPos ;
668
+ newCurrentStake = newInitPos + newTotalPos ;
669
+ one .setInitPos (newInitPos );
666
670
one .setTotalPos (newTotalPos );
667
671
one .setCurrentStake (newCurrentStake );
668
672
// 候选节点顶掉共识的情况
@@ -692,8 +696,10 @@ public InspireResultDto calculationUserIncentives(UserInspireCalculationDto dto)
692
696
BigDecimal newSr = BigDecimal .ZERO ;
693
697
String initProportion = calculationNode .getNodeProportion ().replace ("%" , "" );
694
698
String stakeProportion = calculationNode .getUserProportion ().replace ("%" , "" );
695
- BigDecimal initUserProportion = new BigDecimal (initProportion ).divide (new BigDecimal (100 ), 2 , BigDecimal .ROUND_HALF_UP );
696
- BigDecimal stakeUserProportion = new BigDecimal (stakeProportion ).divide (new BigDecimal (100 ), 2 , BigDecimal .ROUND_HALF_UP );
699
+ BigDecimal initUserProportion = new BigDecimal (initProportion ).divide (new BigDecimal (100 ), 2 , RoundingMode .HALF_UP );
700
+ BigDecimal initNodeProportion = new BigDecimal (1 ).subtract (initUserProportion );
701
+ BigDecimal stakeUserProportion = new BigDecimal (stakeProportion ).divide (new BigDecimal (100 ), 2 , RoundingMode .HALF_UP );
702
+ BigDecimal stakeNodeProportion = new BigDecimal (1 ).subtract (stakeUserProportion );
697
703
if (foundationNodes .contains (publicKey )) {
698
704
initSDK ();
699
705
Long fu = 0L ;
@@ -708,13 +714,13 @@ public InspireResultDto calculationUserIncentives(UserInspireCalculationDto dto)
708
714
}
709
715
710
716
// old sr
711
- BigDecimal decimal1 = initUserProportion .multiply (new BigDecimal (fu * oldCurrentStake )).divide (new BigDecimal (oldCurrentStake - fp ), 12 , BigDecimal . ROUND_HALF_UP );
717
+ BigDecimal decimal1 = initUserProportion .multiply (new BigDecimal (fu * oldCurrentStake )).divide (new BigDecimal (oldCurrentStake - fp ), 12 , RoundingMode . HALF_UP );
712
718
BigDecimal subtract1 = new BigDecimal (1 ).subtract (initUserProportion );
713
719
BigDecimal decimal2 = new BigDecimal (fp ).multiply (subtract1 );
714
720
oldSr = decimal1 .add (decimal2 );
715
721
716
722
// new sr
717
- BigDecimal decimal3 = initUserProportion .multiply (new BigDecimal (fu * newCurrentStake )).divide (new BigDecimal (newCurrentStake - fp ), 12 , BigDecimal . ROUND_HALF_UP );
723
+ BigDecimal decimal3 = initUserProportion .multiply (new BigDecimal (fu * newCurrentStake )).divide (new BigDecimal (newCurrentStake - fp ), 12 , RoundingMode . HALF_UP );
718
724
BigDecimal subtract2 = new BigDecimal (1 ).subtract (initUserProportion );
719
725
BigDecimal decimal4 = new BigDecimal (fp ).multiply (subtract2 );
720
726
newSr = decimal3 .add (decimal4 );
@@ -739,7 +745,7 @@ public InspireResultDto calculationUserIncentives(UserInspireCalculationDto dto)
739
745
BigDecimal topStake = new BigDecimal (top49Stake );
740
746
741
747
// 第一轮
742
- BigDecimal first = new BigDecimal (10000000 ).divide (topStake , 12 , BigDecimal . ROUND_HALF_UP );
748
+ BigDecimal first = new BigDecimal (10000000 ).divide (topStake , 12 , RoundingMode . HALF_UP );
743
749
// 第二轮 数据库获取
744
750
List <InspireCalculationParams > inspireCalculationParams = inspireCalculationParamsMapper .selectAll ();
745
751
if (CollectionUtils .isEmpty (inspireCalculationParams )) {
@@ -752,15 +758,15 @@ public InspireResultDto calculationUserIncentives(UserInspireCalculationDto dto)
752
758
BigDecimal ont = params .getOntPrice ();
753
759
BigDecimal ong = params .getOngPrice ();
754
760
BigDecimal subtract = topStake .subtract (totalFpFu );
755
- BigDecimal second = totalSr .divide (subtract , 12 , BigDecimal . ROUND_HALF_UP );
761
+ BigDecimal second = totalSr .divide (subtract , 12 , RoundingMode . HALF_UP );
756
762
757
763
// 候选节点的质押总和
758
764
BigDecimal candidateTotalStake = getTotalStake (candidateNodes );
759
765
760
766
BigDecimal consensusTotalStake = getTotalStake (consensusNodes );
761
767
BigDecimal consensusCount = new BigDecimal (consensusNodes .size ());
762
768
// 共识节点的平均质押量
763
- BigDecimal consensusAverageStake = consensusTotalStake .divide (consensusCount , 12 , BigDecimal . ROUND_HALF_UP );
769
+ BigDecimal consensusAverageStake = consensusTotalStake .divide (consensusCount , 12 , RoundingMode . HALF_UP );
764
770
765
771
// A 为所有共识节点的激励系数总和
766
772
Map <String , BigDecimal > consensusInspireMap = new HashMap <>();
@@ -777,6 +783,7 @@ public InspireResultDto calculationUserIncentives(UserInspireCalculationDto dto)
777
783
BigDecimal finalReleaseOng = BigDecimal .ZERO ;
778
784
BigDecimal finalCommission = BigDecimal .ZERO ;
779
785
BigDecimal userFoundationInspire = BigDecimal .ZERO ;
786
+ BigDecimal nodeFoundationInspire = BigDecimal .ZERO ;
780
787
781
788
Integer status = calculationNode .getStatus ();
782
789
@@ -802,30 +809,49 @@ public InspireResultDto calculationUserIncentives(UserInspireCalculationDto dto)
802
809
BigDecimal siSubFp = currentStake .subtract (fp );
803
810
// 用户收益
804
811
BigDecimal siPb = currentStake .multiply (initUserProportion );
805
- BigDecimal add = siPb .divide (siSubFp , 12 , BigDecimal . ROUND_HALF_UP ).add (second );
812
+ BigDecimal add = siPb .divide (siSubFp , 12 , RoundingMode . HALF_UP ).add (second );
806
813
userFoundationInspire = first .multiply (stakeAmountDecimal ).multiply (add );
807
814
}
808
815
if (totalPos .compareTo (BigDecimal .ZERO ) == 0 ) {
809
816
totalPos = new BigDecimal (1 );
810
817
}
811
- BigDecimal userStakePercentInTotalPos = stakeAmountDecimal .divide (totalPos , 12 , BigDecimal . ROUND_HALF_UP );
812
- BigDecimal initPercent = nodeStake .divide (currentStake , 12 , BigDecimal . ROUND_HALF_UP );
813
- BigDecimal stakePercent = totalPos .divide (currentStake , 12 , BigDecimal . ROUND_HALF_UP );
818
+ BigDecimal userStakePercentInTotalPos = stakeAmountDecimal .divide (totalPos , 12 , RoundingMode . HALF_UP );
819
+ BigDecimal initPercent = nodeStake .divide (currentStake , 12 , RoundingMode . HALF_UP );
820
+ BigDecimal stakePercent = totalPos .divide (currentStake , 12 , RoundingMode . HALF_UP );
814
821
815
822
BigDecimal initPartFinalReleaseOng = finalReleaseOng .multiply (initPercent );
816
823
BigDecimal stakePartFinalReleaseOng = finalReleaseOng .multiply (stakePercent );
817
824
818
825
BigDecimal initPartFinalCommission = finalCommission .multiply (initPercent );
819
826
BigDecimal stakePartFinalCommission = finalCommission .multiply (stakePercent );
820
827
828
+ BigDecimal finalNodeReleaseOng = ((initPartFinalReleaseOng .multiply (initNodeProportion )).add ((stakePartFinalReleaseOng .multiply (stakeNodeProportion ))));
821
829
BigDecimal finalUserReleaseOng = ((initPartFinalReleaseOng .multiply (initUserProportion )).add ((stakePartFinalReleaseOng .multiply (stakeUserProportion )))).multiply (userStakePercentInTotalPos );
830
+ BigDecimal finalNodeCommission = ((initPartFinalCommission .multiply (initNodeProportion )).add ((stakePartFinalCommission .multiply (stakeNodeProportion ))));
822
831
BigDecimal finalUserCommission = ((initPartFinalCommission .multiply (initUserProportion )).add ((stakePartFinalCommission .multiply (stakeUserProportion )))).multiply (userStakePercentInTotalPos );
823
832
824
- BigDecimal stakeAmountUsd = stakeAmountDecimal .multiply (ont );
833
+ BigDecimal nodeStakeAmountUsd = nodeStake .multiply (ont );
834
+ BigDecimal nodeReleaseUsd = finalNodeReleaseOng .multiply (ong );
835
+ BigDecimal nodeCommissionUsd = finalNodeCommission .multiply (ong );
836
+ BigDecimal nodeFoundationUsd = nodeFoundationInspire .multiply (ong );
837
+ BigDecimal userStakeAmountUsd = stakeAmountDecimal .multiply (ont );
825
838
BigDecimal userReleaseUsd = finalUserReleaseOng .multiply (ong );
826
839
BigDecimal userCommissionUsd = finalUserCommission .multiply (ong );
827
840
BigDecimal userFoundationUsd = userFoundationInspire .multiply (ong );
828
841
842
+ if (initPos > 0 ) {
843
+ nodeInspire .setNodeReleasedOngIncentive (finalNodeReleaseOng .setScale (4 , RoundingMode .DOWN ).toPlainString ());
844
+ nodeInspire .setNodeGasFeeIncentive (finalNodeCommission .setScale (4 , RoundingMode .DOWN ).toPlainString ());
845
+ nodeInspire .setNodeFoundationBonusIncentive (nodeFoundationInspire .setScale (4 , RoundingMode .DOWN ).toPlainString ());
846
+ BigDecimal nodeReleasedOngIncentiveRate = nodeReleaseUsd .divide (nodeStakeAmountUsd , 12 , RoundingMode .HALF_UP ).multiply (oneHundred ).setScale (2 , RoundingMode .HALF_UP );
847
+ BigDecimal nodeGasFeeIncentiveRate = nodeCommissionUsd .divide (nodeStakeAmountUsd , 12 , RoundingMode .HALF_UP ).multiply (oneHundred ).setScale (2 , RoundingMode .HALF_UP );
848
+ BigDecimal nodeFoundationBonusIncentiveRate = nodeFoundationUsd .divide (nodeStakeAmountUsd , 12 , RoundingMode .HALF_UP ).multiply (oneHundred ).setScale (2 , RoundingMode .HALF_UP );
849
+ String nodeApr = nodeReleasedOngIncentiveRate .add (nodeGasFeeIncentiveRate ).add (nodeFoundationBonusIncentiveRate ).toPlainString () + "%" ;
850
+ nodeInspire .setNodeReleasedOngIncentiveRate (nodeReleasedOngIncentiveRate .toPlainString () + "%" );
851
+ nodeInspire .setNodeGasFeeIncentiveRate (nodeGasFeeIncentiveRate .toPlainString () + "%" );
852
+ nodeInspire .setNodeFoundationBonusIncentiveRate (nodeFoundationBonusIncentiveRate .toPlainString () + "%" );
853
+ nodeInspire .setNodeApr (nodeApr );
854
+ }
829
855
Long maxAuthorize = calculationNode .getMaxAuthorize ();
830
856
// 考虑此节点用户质押部分满了的情况,此时用户不能再进行质押,收益为0
831
857
if (maxAuthorize == 0 && totalPos1 == 0 ) {
@@ -835,13 +861,19 @@ public InspireResultDto calculationUserIncentives(UserInspireCalculationDto dto)
835
861
nodeInspire .setUserReleasedOngIncentiveRate ("0.00%" );
836
862
nodeInspire .setUserGasFeeIncentiveRate ("0.00%" );
837
863
nodeInspire .setUserFoundationBonusIncentiveRate ("0.00%" );
864
+ nodeInspire .setUserApr ("0.00%" );
838
865
} else {
839
- nodeInspire .setUserReleasedOngIncentive (finalUserReleaseOng .setScale (4 , BigDecimal .ROUND_DOWN ).toPlainString ());
840
- nodeInspire .setUserGasFeeIncentive (finalUserCommission .setScale (4 , BigDecimal .ROUND_DOWN ).toPlainString ());
841
- nodeInspire .setUserFoundationBonusIncentive (userFoundationInspire .setScale (4 , BigDecimal .ROUND_DOWN ).toPlainString ());
842
- nodeInspire .setUserReleasedOngIncentiveRate (userReleaseUsd .divide (stakeAmountUsd , 12 , BigDecimal .ROUND_HALF_UP ).multiply (oneHundred ).setScale (2 , BigDecimal .ROUND_HALF_UP ).toPlainString () + "%" );
843
- nodeInspire .setUserGasFeeIncentiveRate (userCommissionUsd .divide (stakeAmountUsd , 12 , BigDecimal .ROUND_HALF_UP ).multiply (oneHundred ).setScale (2 , BigDecimal .ROUND_HALF_UP ).toPlainString () + "%" );
844
- nodeInspire .setUserFoundationBonusIncentiveRate (userFoundationUsd .divide (stakeAmountUsd , 12 , BigDecimal .ROUND_HALF_UP ).multiply (oneHundred ).setScale (2 , BigDecimal .ROUND_HALF_UP ).toPlainString () + "%" );
866
+ nodeInspire .setUserReleasedOngIncentive (finalUserReleaseOng .setScale (4 , RoundingMode .DOWN ).toPlainString ());
867
+ nodeInspire .setUserGasFeeIncentive (finalUserCommission .setScale (4 , RoundingMode .DOWN ).toPlainString ());
868
+ nodeInspire .setUserFoundationBonusIncentive (userFoundationInspire .setScale (4 , RoundingMode .DOWN ).toPlainString ());
869
+ BigDecimal userReleasedOngIncentiveRate = userReleaseUsd .divide (userStakeAmountUsd , 12 , RoundingMode .HALF_UP ).multiply (oneHundred ).setScale (2 , RoundingMode .HALF_UP );
870
+ BigDecimal userGasFeeIncentiveRate = userCommissionUsd .divide (userStakeAmountUsd , 12 , RoundingMode .HALF_UP ).multiply (oneHundred ).setScale (2 , RoundingMode .HALF_UP );
871
+ BigDecimal userFoundationBonusIncentiveRate = userFoundationUsd .divide (userStakeAmountUsd , 12 , RoundingMode .HALF_UP ).multiply (oneHundred ).setScale (2 , RoundingMode .HALF_UP );
872
+ String userApr = userReleasedOngIncentiveRate .add (userGasFeeIncentiveRate ).add (userFoundationBonusIncentiveRate ).toPlainString () + "%" ;
873
+ nodeInspire .setUserReleasedOngIncentiveRate (userReleasedOngIncentiveRate .toPlainString () + "%" );
874
+ nodeInspire .setUserGasFeeIncentiveRate (userGasFeeIncentiveRate .toPlainString () + "%" );
875
+ nodeInspire .setUserFoundationBonusIncentiveRate (userFoundationBonusIncentiveRate .toPlainString () + "%" );
876
+ nodeInspire .setUserApr (userApr );
845
877
}
846
878
847
879
return nodeInspire ;
@@ -1002,10 +1034,24 @@ public PageResponseBean getNodesByFilter(NodesInfoDto dto) {
1002
1034
1003
1035
@ Override
1004
1036
public ResponseBean getAddressRegisterNodeList (String address ) {
1037
+ RegisterNodeDto result = new RegisterNodeDto ();
1038
+ initSDK ();
1039
+ try {
1040
+ String splitFeeStr = sdk .getSplitFee (address );
1041
+ if (StringUtils .hasLength (splitFeeStr )) {
1042
+ JSONObject splitFee = JSONObject .parseObject (splitFeeStr );
1043
+ String reward = splitFee .getBigDecimal ("amount" ).divide (ConstantParam .NINE_BIT_DECIMAL , 9 , RoundingMode .DOWN ).stripTrailingZeros ().toPlainString ();
1044
+ result .setReward (reward );
1045
+ }
1046
+ } catch (Exception e ) {
1047
+ log .error ("getAddressRegisterNodeInfo error:{},{}" , address , e .getMessage ());
1048
+ }
1049
+
1005
1050
List <NodeInfoOffChain > registerNodeList = nodeInfoOffChainMapper .selectAllRegisterNodeInfo (address );
1051
+ List <NodeInfoOffChain > list = Collections .emptyList ();
1006
1052
if (!CollectionUtils .isEmpty (registerNodeList )) {
1053
+ list = new ArrayList <>();
1007
1054
try {
1008
- initSDK ();
1009
1055
Map peerPoolMap = sdk .getPeerPoolMap ();
1010
1056
for (NodeInfoOffChain registerNodeInfo : registerNodeList ) {
1011
1057
String publicKey = registerNodeInfo .getPublicKey ();
@@ -1027,17 +1073,36 @@ public ResponseBean getAddressRegisterNodeList(String address) {
1027
1073
if (StringUtils .hasLength (authorizeInfo )) {
1028
1074
JSONObject jsonObject = JSONObject .parseObject (authorizeInfo );
1029
1075
initPos = jsonObject .getLong ("withdrawUnfreezePos" );
1076
+ } else {
1077
+ continue ;
1030
1078
}
1031
1079
}
1032
1080
registerNodeInfo .setStatus (status );
1033
1081
registerNodeInfo .setInitPos (initPos );
1034
1082
registerNodeInfo .setTotalPos (totalPos );
1083
+ list .add (registerNodeInfo );
1035
1084
}
1085
+ list .sort ((o1 , o2 ) -> {
1086
+ // 先按照status排序(1-在线->3-已退出->2-正在退出),status相同的情况下按照节点质押数量倒序
1087
+ int compareByPrice = Integer .compare (o1 .getStatus (), o2 .getStatus ());
1088
+ if (compareByPrice != 0 ) {
1089
+ if (o1 .getStatus () == 2 && o2 .getStatus () == 3 ) {
1090
+ return 1 ;
1091
+ } else if (o1 .getStatus () == 3 && o2 .getStatus () == 2 ) {
1092
+ return -1 ;
1093
+ } else {
1094
+ return compareByPrice ;
1095
+ }
1096
+ } else {
1097
+ return Long .compare (o2 .getInitPos (), o1 .getInitPos ());
1098
+ }
1099
+ });
1036
1100
} catch (Exception e ) {
1037
1101
log .error ("getAddressRegisterNodeInfo error:{},{}" , address , e .getMessage ());
1038
1102
}
1039
1103
}
1040
- return new ResponseBean (ErrorInfo .SUCCESS .code (), ErrorInfo .SUCCESS .desc (), registerNodeList );
1104
+ result .setRegisterNodeList (list );
1105
+ return new ResponseBean (ErrorInfo .SUCCESS .code (), ErrorInfo .SUCCESS .desc (), result );
1041
1106
}
1042
1107
1043
1108
@ Override
0 commit comments