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 _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 _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 _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.
|
* @return Amount of minted tokens.
|
||||||
*/
|
*/
|
||||||
// TODO decimals
|
|
||||||
function mint(
|
function mint(
|
||||||
uint256 _period,
|
uint256 _period,
|
||||||
uint256 _lockedValue,
|
uint256 _lockedValue,
|
||||||
uint256 _totalLockedValue,
|
uint256 _totalLockedValue,
|
||||||
uint256 _allLockedPeriods,
|
uint256 _allLockedPeriods
|
||||||
uint256 _decimals
|
|
||||||
)
|
)
|
||||||
internal returns (uint256 amount, uint256 decimals)
|
internal returns (uint256 amount)
|
||||||
{
|
{
|
||||||
// TODO finish method before calculation after end of mining
|
|
||||||
uint256 currentSupply = _period <= lastMintedPeriod ?
|
uint256 currentSupply = _period <= lastMintedPeriod ?
|
||||||
Math.min256(currentSupply1, currentSupply2) :
|
Math.min256(currentSupply1, currentSupply2) :
|
||||||
Math.max256(currentSupply1, currentSupply2);
|
Math.max256(currentSupply1, currentSupply2);
|
||||||
|
if (currentSupply == futureSupply) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//futureSupply * lockedValue * (k1 + allLockedPeriods) / (totalLockedValue * k2) -
|
//futureSupply * lockedValue * (k1 + allLockedPeriods) / (totalLockedValue * k2) -
|
||||||
//currentSupply * lockedValue * (k1 + allLockedPeriods) / (totalLockedValue * k2)
|
//currentSupply * lockedValue * (k1 + allLockedPeriods) / (totalLockedValue * k2)
|
||||||
|
@ -135,7 +134,10 @@ contract Issuer is Upgradeable {
|
||||||
.mul(_lockedValue)
|
.mul(_lockedValue)
|
||||||
.mul(allLockedPeriods)
|
.mul(allLockedPeriods)
|
||||||
.div(denominator));
|
.div(denominator));
|
||||||
decimals = _decimals;
|
// rounding the last reward
|
||||||
|
if (amount == 0) {
|
||||||
|
amount = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (_period <= lastMintedPeriod) {
|
if (_period <= lastMintedPeriod) {
|
||||||
if (currentSupply1 > currentSupply2) {
|
if (currentSupply1 > currentSupply2) {
|
||||||
|
|
|
@ -50,7 +50,6 @@ contract MinersEscrow is Issuer {
|
||||||
|
|
||||||
struct MinerInfo {
|
struct MinerInfo {
|
||||||
uint256 value;
|
uint256 value;
|
||||||
uint256 decimals;
|
|
||||||
/*
|
/*
|
||||||
* Periods that confirmed but not yet mined, two values instead of array for optimisation.
|
* 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
|
* 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)
|
internal returns (uint256 reward)
|
||||||
{
|
{
|
||||||
uint256 amount;
|
|
||||||
for (uint256 i = 0; i < _info.stakes.length; i++) {
|
for (uint256 i = 0; i < _info.stakes.length; i++) {
|
||||||
StakeInfo storage stake = _info.stakes[i];
|
StakeInfo storage stake = _info.stakes[i];
|
||||||
uint256 lastPeriod = getLastPeriod(stake, _startPeriod);
|
uint256 lastPeriod = getLastPeriod(stake, _startPeriod);
|
||||||
if (stake.firstPeriod <= _period && lastPeriod >= _period) {
|
if (stake.firstPeriod <= _period && lastPeriod >= _period) {
|
||||||
(amount, _info.decimals) = mint(
|
reward = reward.add(mint(
|
||||||
_previousPeriod,
|
_previousPeriod,
|
||||||
stake.lockedValue,
|
stake.lockedValue,
|
||||||
lockedPerPeriod[_period],
|
lockedPerPeriod[_period],
|
||||||
lastPeriod.sub(_period),
|
lastPeriod.sub(_period)));
|
||||||
_info.decimals);
|
|
||||||
reward = reward.add(amount);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
policyManager.updateReward(_owner, _period);
|
policyManager.updateReward(_owner, _period);
|
||||||
|
@ -720,7 +716,6 @@ contract MinersEscrow is Issuer {
|
||||||
MinerInfo storage info = minerInfo[minerAddress];
|
MinerInfo storage info = minerInfo[minerAddress];
|
||||||
MinerInfo memory infoToCheck = delegateGetMinerInfo(_testTarget, minerAddress);
|
MinerInfo memory infoToCheck = delegateGetMinerInfo(_testTarget, minerAddress);
|
||||||
require(infoToCheck.value == info.value &&
|
require(infoToCheck.value == info.value &&
|
||||||
infoToCheck.decimals == info.decimals &&
|
|
||||||
infoToCheck.confirmedPeriod1 == info.confirmedPeriod1 &&
|
infoToCheck.confirmedPeriod1 == info.confirmedPeriod1 &&
|
||||||
infoToCheck.confirmedPeriod2 == info.confirmedPeriod2 &&
|
infoToCheck.confirmedPeriod2 == info.confirmedPeriod2 &&
|
||||||
infoToCheck.lastActivePeriod == info.lastActivePeriod);
|
infoToCheck.lastActivePeriod == info.lastActivePeriod);
|
||||||
|
|
|
@ -330,7 +330,7 @@ contract PolicyManager is Upgradeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 lastActivePeriod;
|
uint256 lastActivePeriod;
|
||||||
(,,,,lastActivePeriod) = escrow.minerInfo(_node);
|
(,,,lastActivePeriod) = escrow.minerInfo(_node);
|
||||||
if (i == length && lastActivePeriod < maxPeriod) {
|
if (i == length && lastActivePeriod < maxPeriod) {
|
||||||
downtimePeriods = downtimePeriods.add(
|
downtimePeriods = downtimePeriods.add(
|
||||||
maxPeriod.sub(Math.max256(
|
maxPeriod.sub(Math.max256(
|
||||||
|
|
|
@ -32,17 +32,15 @@ contract IssuerMock is Issuer {
|
||||||
uint256 _period,
|
uint256 _period,
|
||||||
uint256 _lockedValue,
|
uint256 _lockedValue,
|
||||||
uint256 _totalLockedValue,
|
uint256 _totalLockedValue,
|
||||||
uint256 _allLockedPeriods,
|
uint256 _allLockedPeriods
|
||||||
uint256 _decimals
|
|
||||||
)
|
)
|
||||||
public returns (uint256 amount, uint256 decimals)
|
public returns (uint256 amount)
|
||||||
{
|
{
|
||||||
(amount, decimals) = mint(
|
amount = mint(
|
||||||
_period,
|
_period,
|
||||||
_lockedValue,
|
_lockedValue,
|
||||||
_totalLockedValue,
|
_totalLockedValue,
|
||||||
_allLockedPeriods,
|
_allLockedPeriods);
|
||||||
_decimals);
|
|
||||||
token.transfer(msg.sender, amount);
|
token.transfer(msg.sender, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ contract MinersEscrowForPolicyMock {
|
||||||
* @notice Emulate minerInfo
|
* @notice Emulate minerInfo
|
||||||
**/
|
**/
|
||||||
function minerInfo(address)
|
function minerInfo(address)
|
||||||
public view returns (uint256, uint256, uint256, uint256, uint256 result)
|
public view returns (uint256, uint256, uint256, uint256 result)
|
||||||
{
|
{
|
||||||
result = lastActivePeriod;
|
result = lastActivePeriod;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,23 +40,23 @@ def test_issuer(web3, chain, token):
|
||||||
chain.wait_for_receipt(tx)
|
chain.wait_for_receipt(tx)
|
||||||
|
|
||||||
# Mint some tokens
|
# 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)
|
chain.wait_for_receipt(tx)
|
||||||
assert 10 == token.functions.balanceOf(ursula).call()
|
assert 10 == token.functions.balanceOf(ursula).call()
|
||||||
assert balance - 10 == token.functions.balanceOf(issuer.address).call()
|
assert balance - 10 == token.functions.balanceOf(issuer.address).call()
|
||||||
|
|
||||||
# Mint more tokens
|
# 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)
|
chain.wait_for_receipt(tx)
|
||||||
assert 30 == token.functions.balanceOf(ursula).call()
|
assert 30 == token.functions.balanceOf(ursula).call()
|
||||||
assert balance - 30 == token.functions.balanceOf(issuer.address).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)
|
chain.wait_for_receipt(tx)
|
||||||
assert 70 == token.functions.balanceOf(ursula).call()
|
assert 70 == token.functions.balanceOf(ursula).call()
|
||||||
assert balance - 70 == token.functions.balanceOf(issuer.address).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)
|
chain.wait_for_receipt(tx)
|
||||||
assert 110 == token.functions.balanceOf(ursula).call()
|
assert 110 == token.functions.balanceOf(ursula).call()
|
||||||
assert balance - 110 == token.functions.balanceOf(issuer.address).call()
|
assert balance - 110 == token.functions.balanceOf(issuer.address).call()
|
||||||
|
@ -80,28 +80,28 @@ def test_inflation_rate(web3, chain, token):
|
||||||
|
|
||||||
# Mint some tokens
|
# Mint some tokens
|
||||||
period = issuer.functions.getCurrentPeriod().call()
|
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)
|
chain.wait_for_receipt(tx)
|
||||||
one_period = token.functions.balanceOf(ursula).call()
|
one_period = token.functions.balanceOf(ursula).call()
|
||||||
|
|
||||||
# Mint more tokens in the same period
|
# 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)
|
chain.wait_for_receipt(tx)
|
||||||
assert 2 * one_period == token.functions.balanceOf(ursula).call()
|
assert 2 * one_period == token.functions.balanceOf(ursula).call()
|
||||||
|
|
||||||
# Mint tokens in the next period
|
# 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)
|
chain.wait_for_receipt(tx)
|
||||||
assert 3 * one_period > token.functions.balanceOf(ursula).call()
|
assert 3 * one_period > token.functions.balanceOf(ursula).call()
|
||||||
minted_amount = token.functions.balanceOf(ursula).call() - 2 * one_period
|
minted_amount = token.functions.balanceOf(ursula).call() - 2 * one_period
|
||||||
|
|
||||||
# Mint tokens in the next 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)
|
chain.wait_for_receipt(tx)
|
||||||
assert 2 * one_period + 2 * minted_amount == token.functions.balanceOf(ursula).call()
|
assert 2 * one_period + 2 * minted_amount == token.functions.balanceOf(ursula).call()
|
||||||
|
|
||||||
# Mint tokens in the next period
|
# 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)
|
chain.wait_for_receipt(tx)
|
||||||
assert 2 * one_period + 3 * minted_amount > token.functions.balanceOf(ursula).call()
|
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
|
# Ursula can't use method from Issuer contract
|
||||||
with pytest.raises(Exception):
|
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)
|
chain.wait_for_receipt(tx)
|
||||||
|
|
||||||
# Only Ursula confirm next period
|
# Only Ursula confirm next period
|
||||||
|
|
Loading…
Reference in New Issue