@@ -33,16 +33,14 @@ contract CloversController is HasNoEther, HasNoTokens {
33
33
address public curationMarket;
34
34
35
35
uint256 public gasLastUpdated_fastGasPrice_averageGasPrice_safeLowGasPrice;
36
- // uint256 memory public gasLastUpdated;
37
- // uint256 memory public fastGasPrice;
38
- // uint256 memory public averageGasPrice;
39
- // uint256 memory public safeLowGasPrice;
40
36
41
37
uint256 public basePrice;
42
38
uint256 public priceMultiplier;
43
39
uint256 public payMultiplier;
44
40
uint256 public stakeAmount;
45
41
uint256 public stakePeriod;
42
+ uint256 public constant oneGwei = 1000000000 ;
43
+ uint256 public gasBlockMargin = 240 ; // ~1 hour at 15 second blocks
46
44
47
45
struct Commit {
48
46
bool collected;
@@ -196,6 +194,10 @@ contract CloversController is HasNoEther, HasNoTokens {
196
194
return basePrice.add (calculateReward (_symmetries));
197
195
}
198
196
197
+ function updateGasBlockMargin (uint256 _gasBlockMargin ) public onlyOwnerOrOracle {
198
+ gasBlockMargin = _gasBlockMargin;
199
+ }
200
+
199
201
function updateGasPrices (uint256 _fastGasPrice , uint256 _averageGasPrice , uint256 _safeLowGasPrice ) public onlyOwnerOrOracle {
200
202
uint256 gasLastUpdated = block .number << 192 ;
201
203
uint256 fastGasPrice = _fastGasPrice << 128 ;
@@ -205,7 +207,6 @@ contract CloversController is HasNoEther, HasNoTokens {
205
207
}
206
208
207
209
function gasLastUpdated () public view returns (uint256 ) {
208
-
209
210
return uint256 (uint64 (gasLastUpdated_fastGasPrice_averageGasPrice_safeLowGasPrice >> 192 ));
210
211
}
211
212
function fastGasPrice () public view returns (uint256 ) {
@@ -217,6 +218,13 @@ contract CloversController is HasNoEther, HasNoTokens {
217
218
function safeLowGasPrice () public view returns (uint256 ) {
218
219
return uint256 (uint64 (gasLastUpdated_fastGasPrice_averageGasPrice_safeLowGasPrice));
219
220
}
221
+ function getGasPriceForApp () public view returns (uint256 ) {
222
+ if (block .number .sub (gasLastUpdated ()) > gasBlockMargin) {
223
+ return oneGwei.mul (10 );
224
+ } else {
225
+ return fastGasPrice ();
226
+ }
227
+ }
220
228
221
229
/**
222
230
* @dev Claim the Clover without a commit or reveal. Payable so you can attach enough for the stake,
@@ -233,8 +241,7 @@ contract CloversController is HasNoEther, HasNoTokens {
233
241
234
242
bytes32 movesHash = keccak256 (moves);
235
243
236
- uint256 fastGasPrice = uint256 (uint64 (gasLastUpdated_fastGasPrice_averageGasPrice_safeLowGasPrice >> 128 ));
237
- uint256 stakeWithGas = stakeAmount.mul (fastGasPrice);
244
+ uint256 stakeWithGas = stakeAmount.mul (getGasPriceForApp ());
238
245
require (msg .value >= stakeWithGas);
239
246
require (getCommit (movesHash) == 0 );
240
247
0 commit comments