mirror of https://github.com/nucypher/nucypher.git
Removes reward decimals
parent
a97f720b24
commit
b41294c4e3
|
@ -102,23 +102,22 @@ contract Issuer is Upgradeable {
|
|||
* @param _lockedValue The amount of tokens that were locked by user in specified period.
|
||||
* @param _totalLockedValue The amount of tokens that were locked by all users in specified period.
|
||||
* @param _allLockedPeriods The max amount of periods during which tokens will be locked after specified period.
|
||||
* @param _decimals The amount of locked tokens and blocks in decimals.
|
||||
* @return Amount of minted tokens.
|
||||
*/
|
||||
// TODO decimals
|
||||
function mint(
|
||||
uint256 _period,
|
||||
uint256 _lockedValue,
|
||||
uint256 _totalLockedValue,
|
||||
uint256 _allLockedPeriods,
|
||||
uint256 _decimals
|
||||
uint256 _allLockedPeriods
|
||||
)
|
||||
internal returns (uint256 amount, uint256 decimals)
|
||||
internal returns (uint256 amount)
|
||||
{
|
||||
// TODO finish method before calculation after end of mining
|
||||
uint256 currentSupply = _period <= lastMintedPeriod ?
|
||||
Math.min256(currentSupply1, currentSupply2) :
|
||||
Math.max256(currentSupply1, currentSupply2);
|
||||
if (currentSupply == futureSupply) {
|
||||
return;
|
||||
}
|
||||
|
||||
//futureSupply * lockedValue * (k1 + allLockedPeriods) / (totalLockedValue * k2) -
|
||||
//currentSupply * lockedValue * (k1 + allLockedPeriods) / (totalLockedValue * k2)
|
||||
|
@ -135,7 +134,10 @@ contract Issuer is Upgradeable {
|
|||
.mul(_lockedValue)
|
||||
.mul(allLockedPeriods)
|
||||
.div(denominator));
|
||||
decimals = _decimals;
|
||||
// rounding the last reward
|
||||
if (amount == 0) {
|
||||
amount = 1;
|
||||
}
|
||||
|
||||
if (_period <= lastMintedPeriod) {
|
||||
if (currentSupply1 > currentSupply2) {
|
||||
|
|
|
@ -50,7 +50,6 @@ contract MinersEscrow is Issuer {
|
|||
|
||||
struct MinerInfo {
|
||||
uint256 value;
|
||||
uint256 decimals;
|
||||
/*
|
||||
* Periods that confirmed but not yet mined, two values instead of array for optimisation.
|
||||
* lock() and confirmActivity() methods include mint() method so may be only two confirmed
|
||||
|
@ -519,18 +518,15 @@ contract MinersEscrow is Issuer {
|
|||
)
|
||||
internal returns (uint256 reward)
|
||||
{
|
||||
uint256 amount;
|
||||
for (uint256 i = 0; i < _info.stakes.length; i++) {
|
||||
StakeInfo storage stake = _info.stakes[i];
|
||||
uint256 lastPeriod = getLastPeriod(stake, _startPeriod);
|
||||
if (stake.firstPeriod <= _period && lastPeriod >= _period) {
|
||||
(amount, _info.decimals) = mint(
|
||||
reward = reward.add(mint(
|
||||
_previousPeriod,
|
||||
stake.lockedValue,
|
||||
lockedPerPeriod[_period],
|
||||
lastPeriod.sub(_period),
|
||||
_info.decimals);
|
||||
reward = reward.add(amount);
|
||||
lastPeriod.sub(_period)));
|
||||
}
|
||||
}
|
||||
policyManager.updateReward(_owner, _period);
|
||||
|
@ -720,7 +716,6 @@ contract MinersEscrow is Issuer {
|
|||
MinerInfo storage info = minerInfo[minerAddress];
|
||||
MinerInfo memory infoToCheck = delegateGetMinerInfo(_testTarget, minerAddress);
|
||||
require(infoToCheck.value == info.value &&
|
||||
infoToCheck.decimals == info.decimals &&
|
||||
infoToCheck.confirmedPeriod1 == info.confirmedPeriod1 &&
|
||||
infoToCheck.confirmedPeriod2 == info.confirmedPeriod2 &&
|
||||
infoToCheck.lastActivePeriod == info.lastActivePeriod);
|
||||
|
|
|
@ -330,7 +330,7 @@ contract PolicyManager is Upgradeable {
|
|||
}
|
||||
|
||||
uint256 lastActivePeriod;
|
||||
(,,,,lastActivePeriod) = escrow.minerInfo(_node);
|
||||
(,,,lastActivePeriod) = escrow.minerInfo(_node);
|
||||
if (i == length && lastActivePeriod < maxPeriod) {
|
||||
downtimePeriods = downtimePeriods.add(
|
||||
maxPeriod.sub(Math.max256(
|
||||
|
|
|
@ -32,17 +32,15 @@ contract IssuerMock is Issuer {
|
|||
uint256 _period,
|
||||
uint256 _lockedValue,
|
||||
uint256 _totalLockedValue,
|
||||
uint256 _allLockedPeriods,
|
||||
uint256 _decimals
|
||||
uint256 _allLockedPeriods
|
||||
)
|
||||
public returns (uint256 amount, uint256 decimals)
|
||||
public returns (uint256 amount)
|
||||
{
|
||||
(amount, decimals) = mint(
|
||||
amount = mint(
|
||||
_period,
|
||||
_lockedValue,
|
||||
_totalLockedValue,
|
||||
_allLockedPeriods,
|
||||
_decimals);
|
||||
_allLockedPeriods);
|
||||
token.transfer(msg.sender, amount);
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ contract MinersEscrowForPolicyMock {
|
|||
* @notice Emulate minerInfo
|
||||
**/
|
||||
function minerInfo(address)
|
||||
public view returns (uint256, uint256, uint256, uint256, uint256 result)
|
||||
public view returns (uint256, uint256, uint256, uint256 result)
|
||||
{
|
||||
result = lastActivePeriod;
|
||||
}
|
||||
|
|
|
@ -40,23 +40,23 @@ def test_issuer(web3, chain, token):
|
|||
chain.wait_for_receipt(tx)
|
||||
|
||||
# Mint some tokens
|
||||
tx = issuer.functions.testMint(0, 1000, 2000, 0, 0).transact({'from': ursula})
|
||||
tx = issuer.functions.testMint(0, 1000, 2000, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 10 == token.functions.balanceOf(ursula).call()
|
||||
assert balance - 10 == token.functions.balanceOf(issuer.address).call()
|
||||
|
||||
# Mint more tokens
|
||||
tx = issuer.functions.testMint(0, 500, 500, 0, 0).transact({'from': ursula})
|
||||
tx = issuer.functions.testMint(0, 500, 500, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 30 == token.functions.balanceOf(ursula).call()
|
||||
assert balance - 30 == token.functions.balanceOf(issuer.address).call()
|
||||
|
||||
tx = issuer.functions.testMint(0, 500, 500, 10 ** 7, 0).transact({'from': ursula})
|
||||
tx = issuer.functions.testMint(0, 500, 500, 10 ** 7).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 70 == token.functions.balanceOf(ursula).call()
|
||||
assert balance - 70 == token.functions.balanceOf(issuer.address).call()
|
||||
|
||||
tx = issuer.functions.testMint(0, 500, 500, 2 * 10 ** 7, 0).transact({'from': ursula})
|
||||
tx = issuer.functions.testMint(0, 500, 500, 2 * 10 ** 7).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 110 == token.functions.balanceOf(ursula).call()
|
||||
assert balance - 110 == token.functions.balanceOf(issuer.address).call()
|
||||
|
@ -80,28 +80,28 @@ def test_inflation_rate(web3, chain, token):
|
|||
|
||||
# Mint some tokens
|
||||
period = issuer.functions.getCurrentPeriod().call()
|
||||
tx = issuer.functions.testMint(period + 1, 1, 1, 0, 0).transact({'from': ursula})
|
||||
tx = issuer.functions.testMint(period + 1, 1, 1, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
one_period = token.functions.balanceOf(ursula).call()
|
||||
|
||||
# Mint more tokens in the same period
|
||||
tx = issuer.functions.testMint(period + 1, 1, 1, 0, 0).transact({'from': ursula})
|
||||
tx = issuer.functions.testMint(period + 1, 1, 1, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 2 * one_period == token.functions.balanceOf(ursula).call()
|
||||
|
||||
# Mint tokens in the next period
|
||||
tx = issuer.functions.testMint(period + 2, 1, 1, 0, 0).transact({'from': ursula})
|
||||
tx = issuer.functions.testMint(period + 2, 1, 1, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 3 * one_period > token.functions.balanceOf(ursula).call()
|
||||
minted_amount = token.functions.balanceOf(ursula).call() - 2 * one_period
|
||||
|
||||
# Mint tokens in the next period
|
||||
tx = issuer.functions.testMint(period + 1, 1, 1, 0, 0).transact({'from': ursula})
|
||||
tx = issuer.functions.testMint(period + 1, 1, 1, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 2 * one_period + 2 * minted_amount == token.functions.balanceOf(ursula).call()
|
||||
|
||||
# Mint tokens in the next period
|
||||
tx = issuer.functions.testMint(period + 3, 1, 1, 0, 0).transact({'from': ursula})
|
||||
tx = issuer.functions.testMint(period + 3, 1, 1, 0).transact({'from': ursula})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 2 * one_period + 3 * minted_amount > token.functions.balanceOf(ursula).call()
|
||||
|
||||
|
|
|
@ -540,7 +540,7 @@ def test_mining(web3, chain, token, escrow_contract):
|
|||
|
||||
# Ursula can't use method from Issuer contract
|
||||
with pytest.raises(Exception):
|
||||
tx = escrow.functions.mint(1, 1, 1, 1, 1).transact({'from': ursula1})
|
||||
tx = escrow.functions.mint(1, 1, 1, 1).transact({'from': ursula1})
|
||||
chain.wait_for_receipt(tx)
|
||||
|
||||
# Only Ursula confirm next period
|
||||
|
|
Loading…
Reference in New Issue