@@ -622,9 +622,6 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
622
622
// Currently, mined represents the number of blocks has mined
623
623
(uint mined , uint totalShares ) = _calcMinedBlocks (pair.sheets, index, sheet);
624
624
625
- // When rewardPerBlock is very large, this calculated may be truncated,
626
- // resulting in a significant reduction in the actual reward,
627
- // This situation is unreasonable and needs to be borne by the opener.
628
625
reward += (
629
626
mined
630
627
* shares
@@ -667,7 +664,7 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
667
664
reward = vault;
668
665
}
669
666
// Record the vault for each channel to prevent the opener use the funds in this contract without increase
670
- channel.vault = uint96 (vault - reward);
667
+ channel.vault = uint128 (vault - reward);
671
668
672
669
// Record reward
673
670
_unfreeze (balances, channel.reward, reward, accountIndex);
@@ -732,12 +729,6 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
732
729
return _calcMinedBlocks (sheets, index, sheets[index]);
733
730
}
734
731
735
- /// @dev The function returns eth rewards of specified ntoken
736
- /// @param channelId Target channelId
737
- function totalETHRewards (uint channelId ) external view override returns (uint ) {
738
- return uint (_channels[channelId].rewards);
739
- }
740
-
741
732
/// @dev Pay
742
733
/// @param channelId Target channelId
743
734
/// @param to Address to receive
@@ -837,9 +828,9 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
837
828
uint prev = uint (p0.height);
838
829
// It's not necessary to load the price information in p0
839
830
// Eth count variable used to calculate price
840
- uint totalEthNum = 0 ;
831
+ uint totalToken0Scales = 0 ;
841
832
// Token count variable for price calculation
842
- uint totalTokenValue = 0 ;
833
+ uint totalToken1Value = 0 ;
843
834
// Block number of current sheet
844
835
uint height = 0 ;
845
836
@@ -866,20 +857,20 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
866
857
// Not the same block (or flag is false), calculate the price and update it
867
858
if (flag || prev != height) {
868
859
869
- // totalEthNum > 0 Can calculate the price
870
- if (totalEthNum > 0 ) {
860
+ // totalToken0Scales > 0 Can calculate the price
861
+ if (totalToken0Scales > 0 ) {
871
862
872
863
// Calculate average price and Volatility
873
864
// Calculation method of volatility of follow-up price
874
865
uint tmp = _decodeFloat (p0.priceFloat);
875
866
// New price
876
- uint price = totalTokenValue / totalEthNum ;
867
+ uint price = totalToken1Value / totalToken0Scales ;
877
868
// Update price
878
- p0.remainScales = uint32 (totalEthNum );
869
+ p0.remainScales = uint32 (totalToken0Scales );
879
870
p0.priceFloat = _encodeFloat (price);
880
871
// Clear cumulative values
881
- totalEthNum = 0 ;
882
- totalTokenValue = 0 ;
872
+ totalToken0Scales = 0 ;
873
+ totalToken1Value = 0 ;
883
874
884
875
if (tmp > 0 ) {
885
876
// Calculate average price
@@ -935,8 +926,8 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
935
926
}
936
927
937
928
// Cumulative price information
938
- totalEthNum += uint (sheet.remainScales);
939
- totalTokenValue += _decodeFloat (sheet.priceFloat) * uint (sheet.remainScales);
929
+ totalToken0Scales += uint (sheet.remainScales);
930
+ totalToken1Value += _decodeFloat (sheet.priceFloat) * uint (sheet.remainScales);
940
931
}
941
932
942
933
// Update price information
@@ -1168,8 +1159,8 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
1168
1159
}
1169
1160
1170
1161
// Calculate price
1171
- uint totalEthNum = 0 ;
1172
- uint totalTokenValue = 0 ;
1162
+ uint totalToken0Scales = 0 ;
1163
+ uint totalToken1Value = 0 ;
1173
1164
uint h = 0 ;
1174
1165
uint remainScales;
1175
1166
PriceSheet memory sheet;
@@ -1189,8 +1180,8 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
1189
1180
} else if (h != sheetHeight) {
1190
1181
break ;
1191
1182
}
1192
- totalEthNum += remainScales;
1193
- totalTokenValue += _decodeFloat (sheet.priceFloat) * remainScales;
1183
+ totalToken0Scales += remainScales;
1184
+ totalToken1Value += _decodeFloat (sheet.priceFloat) * remainScales;
1194
1185
}
1195
1186
}
1196
1187
@@ -1206,13 +1197,13 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
1206
1197
} else if (h != sheetHeight) {
1207
1198
break ;
1208
1199
}
1209
- totalEthNum += remainScales;
1210
- totalTokenValue += _decodeFloat (sheet.priceFloat) * remainScales;
1200
+ totalToken0Scales += remainScales;
1201
+ totalToken1Value += _decodeFloat (sheet.priceFloat) * remainScales;
1211
1202
}
1212
1203
}
1213
1204
1214
- if (totalEthNum > 0 ) {
1215
- return (h + priceEffectSpan, totalTokenValue / totalEthNum );
1205
+ if (totalToken0Scales > 0 ) {
1206
+ return (h + priceEffectSpan, totalToken1Value / totalToken0Scales );
1216
1207
}
1217
1208
return (0 , 0 );
1218
1209
}
@@ -1229,29 +1220,29 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
1229
1220
1230
1221
uint priceEffectSpan = uint (_config.priceEffectSpan);
1231
1222
uint index = sheets.length ;
1232
- uint totalEthNum = 0 ;
1233
- uint totalTokenValue = 0 ;
1223
+ uint totalToken0Scales = 0 ;
1224
+ uint totalToken1Value = 0 ;
1234
1225
uint height = 0 ;
1235
1226
1236
1227
for (uint i = 0 ; i < count;) {
1237
1228
1238
1229
bool flag = index == 0 ;
1239
1230
if (flag || height != uint ((sheet = sheets[-- index]).height)) {
1240
- if (totalEthNum > 0 && height + priceEffectSpan < block .number ) {
1231
+ if (totalToken0Scales > 0 && height + priceEffectSpan < block .number ) {
1241
1232
array[i++ ] = height + priceEffectSpan;
1242
- array[i++ ] = totalTokenValue / totalEthNum ;
1233
+ array[i++ ] = totalToken1Value / totalToken0Scales ;
1243
1234
}
1244
1235
if (flag) {
1245
1236
break ;
1246
1237
}
1247
- totalEthNum = 0 ;
1248
- totalTokenValue = 0 ;
1238
+ totalToken0Scales = 0 ;
1239
+ totalToken1Value = 0 ;
1249
1240
height = uint (sheet.height);
1250
1241
}
1251
1242
1252
1243
uint remainScales = uint (sheet.remainScales);
1253
- totalEthNum += remainScales;
1254
- totalTokenValue += _decodeFloat (sheet.priceFloat) * remainScales;
1244
+ totalToken0Scales += remainScales;
1245
+ totalToken1Value += _decodeFloat (sheet.priceFloat) * remainScales;
1255
1246
}
1256
1247
1257
1248
return array;
0 commit comments