[KMS-ETH]- Decreased gas consumption in mint method

pull/195/head^2
szotov 2018-02-01 19:09:01 +03:00
parent 65073ee473
commit 940f317103
2 changed files with 46 additions and 6 deletions

View File

@ -18,7 +18,9 @@ contract Miner {
uint256 public awardedPeriods;
uint256 public lastMintedPeriod;
uint256 public lastTotalSupply;
mapping (bool => uint256) public totalSupply;
bool public currentIndex;
uint256 futureSupply;
/**
* @notice The Miner constructor sets address of token contract and coefficients for mining
@ -48,6 +50,11 @@ contract Miner {
secondsPerPeriod = _hoursPerPeriod.mul(1 hours);
lockedPeriodsCoefficient = _lockedPeriodsCoefficient;
awardedPeriods = _awardedPeriods;
var currentTotalSupply = token.totalSupply();
totalSupply[currentIndex] = currentTotalSupply;
totalSupply[!currentIndex] = currentTotalSupply;
futureSupply = token.futureSupply();
}
/**
@ -81,9 +88,10 @@ contract Miner {
// TODO end of mining before calculation
// FIXME execution for first owner is more expensive
if (_period > lastMintedPeriod) {
lastTotalSupply = token.totalSupply();
currentIndex != currentIndex;
lastMintedPeriod = _period;
}
var currentTotalSupply = totalSupply[currentIndex];
//futureSupply * lockedValue * (k1 + allLockedPeriods) / (totalLockedValue * k2) -
//currentSupply * lockedValue * (k1 + allLockedPeriods) / (totalLockedValue * k2)
@ -91,15 +99,17 @@ contract Miner {
_allLockedPeriods : awardedPeriods)
.add(lockedPeriodsCoefficient);
var denominator = _totalLockedValue.mul(miningCoefficient);
var maxValue = token.futureSupply()
var maxValue = futureSupply
.mul(_lockedValue)
.mul(allLockedPeriods)
.div(denominator);
var value = lastTotalSupply
var value = currentTotalSupply
.mul(_lockedValue)
.mul(allLockedPeriods)
.div(denominator);
amount = maxValue.sub(value);
token.mint(_to, amount);
totalSupply[!currentIndex] += amount;
}
}

View File

@ -117,7 +117,21 @@ def main():
tx = escrow.transact({'from': ursula3}).mint()
chain.wait.for_receipt(tx)
# Wait 1 period and get locked tokens
# Confirm again
print("First confirm activity again = " +
str(escrow.estimateGas({'from': ursula1}).confirmActivity()))
tx = escrow.transact({'from': ursula1}).confirmActivity()
chain.wait.for_receipt(tx)
print("Second confirm activity again = " +
str(escrow.estimateGas({'from': ursula2}).confirmActivity()))
tx = escrow.transact({'from': ursula2}).confirmActivity()
chain.wait.for_receipt(tx)
print("Third confirm activity again = " +
str(escrow.estimateGas({'from': ursula3}).confirmActivity()))
tx = escrow.transact({'from': ursula3}).confirmActivity()
chain.wait.for_receipt(tx)
# Get locked tokens
print("Getting locked tokens = " +
str(escrow.estimateGas().getLockedTokens(ursula1)))
print("Calculating locked tokens = " +
@ -136,7 +150,8 @@ def main():
str(escrow.estimateGas({'from': ursula3}).switchLock()))
tx = escrow.transact({'from': ursula3}).switchLock()
chain.wait.for_receipt(tx)
#
wait_time(chain, 1)
print("First locking tokens = " +
str(escrow.estimateGas({'from': ursula1}).lock(1, 0)))
tx = escrow.transact({'from': ursula1}).lock(1, 0)
@ -165,6 +180,21 @@ def main():
tx = escrow.transact({'from': ursula3}).withdraw(1)
chain.wait.for_receipt(tx)
# Wait 1 period and confirm activity
wait_time(chain, 1)
print("First confirm activity after downtime = " +
str(escrow.estimateGas({'from': ursula1}).confirmActivity()))
tx = escrow.transact({'from': ursula1}).confirmActivity()
chain.wait.for_receipt(tx)
print("Second confirm activity after downtime = " +
str(escrow.estimateGas({'from': ursula2}).confirmActivity()))
tx = escrow.transact({'from': ursula2}).confirmActivity()
chain.wait.for_receipt(tx)
print("Third confirm activity after downtime = " +
str(escrow.estimateGas({'from': ursula3}).confirmActivity()))
tx = escrow.transact({'from': ursula3}).confirmActivity()
chain.wait.for_receipt(tx)
print("All done!")