Skip to content

Commit ce3f91f

Browse files
committed
maybe ready to deploy
1 parent d2cfa82 commit ce3f91f

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

contracts/CloversController.sol

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ contract CloversController is HasNoEther, HasNoTokens {
3333
address public curationMarket;
3434

3535
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;
4036

4137
uint256 public basePrice;
4238
uint256 public priceMultiplier;
4339
uint256 public payMultiplier;
4440
uint256 public stakeAmount;
4541
uint256 public stakePeriod;
42+
uint256 public constant oneGwei = 1000000000;
43+
uint256 public gasBlockMargin = 240; // ~1 hour at 15 second blocks
4644

4745
struct Commit {
4846
bool collected;
@@ -196,6 +194,10 @@ contract CloversController is HasNoEther, HasNoTokens {
196194
return basePrice.add(calculateReward(_symmetries));
197195
}
198196

197+
function updateGasBlockMargin(uint256 _gasBlockMargin) public onlyOwnerOrOracle {
198+
gasBlockMargin = _gasBlockMargin;
199+
}
200+
199201
function updateGasPrices(uint256 _fastGasPrice, uint256 _averageGasPrice, uint256 _safeLowGasPrice) public onlyOwnerOrOracle {
200202
uint256 gasLastUpdated = block.number << 192;
201203
uint256 fastGasPrice = _fastGasPrice << 128;
@@ -205,7 +207,6 @@ contract CloversController is HasNoEther, HasNoTokens {
205207
}
206208

207209
function gasLastUpdated() public view returns(uint256) {
208-
209210
return uint256(uint64(gasLastUpdated_fastGasPrice_averageGasPrice_safeLowGasPrice >> 192));
210211
}
211212
function fastGasPrice() public view returns(uint256) {
@@ -217,6 +218,13 @@ contract CloversController is HasNoEther, HasNoTokens {
217218
function safeLowGasPrice() public view returns(uint256) {
218219
return uint256(uint64(gasLastUpdated_fastGasPrice_averageGasPrice_safeLowGasPrice));
219220
}
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+
}
220228

221229
/**
222230
* @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 {
233241

234242
bytes32 movesHash = keccak256(moves);
235243

236-
uint256 fastGasPrice = uint256(uint64(gasLastUpdated_fastGasPrice_averageGasPrice_safeLowGasPrice >> 128));
237-
uint256 stakeWithGas = stakeAmount.mul(fastGasPrice);
244+
uint256 stakeWithGas = stakeAmount.mul(getGasPriceForApp());
238245
require(msg.value >= stakeWithGas);
239246
require(getCommit(movesHash) == 0);
240247

helpers/migVals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const utils = require('web3-utils')
33
const oneGwei = 1000000000
44
var vals = (module.exports = {
55
// stakeAmount: new BigNumber(529271).mul(1000000000).mul(40), // gasPrice * 1GWEI * 40 (normal person price)
6-
stakeAmount: new BigNumber(190621).mul(5000000000).mul(1), // gasPrice * 10GWEI (oracle price)
6+
stakeAmount: new BigNumber(190621), // gasPrice * 10GWEI (oracle price)
77
fastGasPrice: new BigNumber(10).mul(oneGwei),
88
averageGasPrice: new BigNumber(5).mul(oneGwei),
99
safeLowGasPrice: new BigNumber(1).mul(oneGwei),

migrations/2_deploy_contracts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const overwrites = {
1313
Support: false,
1414
Clovers: false,
1515
CloversMetadata: false,
16-
CloversController: false,
16+
CloversController: true,
1717
ClubTokenController: false,
1818
SimpleCloversMarket: false,
1919
// CurationMarket: false,

test/CloversController.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ contract('Clovers', async function(accounts) {
981981
})
982982

983983
it('should make sure claimClover (_keep = false) is successful using valid game w/ invalid symmetries', async function() {
984-
var gasPrice = await cloversController.fastGasPrice()
984+
var gasPrice = await cloversController.getGasPriceForApp()
985985
var stakeWithGas = gasPrice.mul(stakeAmount)
986986
try {
987987
let options = [
@@ -1016,7 +1016,7 @@ contract('Clovers', async function(accounts) {
10161016
it('should make sure stake amount was removed from your account', async function() {
10171017
let gasCost = gasSpent * parseInt(globalGasPrice)
10181018
_balance = web3.eth.getBalance(accounts[0])
1019-
var gasPrice = await cloversController.fastGasPrice()
1019+
var gasPrice = await cloversController.getGasPriceForApp()
10201020
var stakeWithGas = gasPrice.mul(stakeAmount)
10211021
assert(
10221022
balance
@@ -1202,7 +1202,7 @@ contract('Clovers', async function(accounts) {
12021202

12031203
let symmetries = rev.returnSymmetriesAsBN()
12041204
let stakeAmount = await cloversController.stakeAmount()
1205-
let gasPrice = await cloversController.fastGasPrice()
1205+
let gasPrice = await cloversController.getGasPriceForApp()
12061206
console.log(`fastGasPrice = ${utils.fromWei(gasPrice.toString(10))} (${gasPrice.toString(10)} wei)`)
12071207
console.log(`stakeAmount = ${utils.fromWei(stakeAmount.toString(10))} (${stakeAmount.toString(10)} wei)`)
12081208

0 commit comments

Comments
 (0)