mirror of https://github.com/nucypher/nucypher.git
StakingEscrow: renames formerSecondsPerPeriod/formerHoursPerPeriod -> genesisSecondsPerPeriod/genesisHoursPerPeriod
parent
2ff93b0eb6
commit
5ba91aef2c
|
@ -56,7 +56,7 @@ class BaseEconomics:
|
|||
|
||||
# Period Definition
|
||||
_default_hours_per_period = 24
|
||||
_default_former_hours_per_period = 24
|
||||
_default_genesis_hours_per_period = 24
|
||||
|
||||
# Time Constraints
|
||||
_default_minimum_worker_periods = 2
|
||||
|
@ -100,7 +100,7 @@ class BaseEconomics:
|
|||
maximum_rewarded_periods: int,
|
||||
first_phase_supply: int,
|
||||
first_phase_max_issuance: int,
|
||||
former_hours_per_period: int = _default_former_hours_per_period,
|
||||
genesis_hours_per_period: int = _default_genesis_hours_per_period,
|
||||
hours_per_period: int = _default_hours_per_period,
|
||||
minimum_locked_periods: int = _default_minimum_locked_periods,
|
||||
minimum_allowed_locked: int = _default_minimum_allowed_locked,
|
||||
|
@ -144,7 +144,7 @@ class BaseEconomics:
|
|||
:param maximum_rewarded_periods: (kmax) Number of periods beyond which a stake's lock duration
|
||||
no longer increases the subsidy it receives. kmax = reward_saturation * 365 where default reward_saturation = 1.
|
||||
See Equation 8 in Staking Protocol & Economics paper.
|
||||
:param former_hours_per_period: Former hours in single period before migration
|
||||
:param genesis_hours_per_period: Hours in single period at genesis
|
||||
:param hours_per_period: Hours in single period
|
||||
:param minimum_locked_periods: Min amount of periods during which tokens can be locked
|
||||
:param minimum_allowed_locked: Min amount of tokens that can be locked
|
||||
|
@ -185,13 +185,13 @@ class BaseEconomics:
|
|||
self.lock_duration_coefficient_1 = lock_duration_coefficient_1
|
||||
self.lock_duration_coefficient_2 = lock_duration_coefficient_2
|
||||
self.maximum_rewarded_periods = maximum_rewarded_periods
|
||||
self.former_hours_per_period = former_hours_per_period
|
||||
self.genesis_hours_per_period = genesis_hours_per_period
|
||||
self.hours_per_period = hours_per_period
|
||||
self.minimum_locked_periods = minimum_locked_periods
|
||||
self.minimum_allowed_locked = minimum_allowed_locked
|
||||
self.maximum_allowed_locked = maximum_allowed_locked
|
||||
self.minimum_worker_periods = minimum_worker_periods
|
||||
self.former_seconds_per_period = former_hours_per_period * 60 * 60 # Former seconds in single period
|
||||
self.genesis_seconds_per_period = genesis_hours_per_period * 60 * 60 # Genesis seconds in single period
|
||||
self.seconds_per_period = hours_per_period * 60 * 60 # Seconds in single period
|
||||
|
||||
#
|
||||
|
@ -222,7 +222,7 @@ class BaseEconomics:
|
|||
deploy_parameters = (
|
||||
|
||||
# Period
|
||||
self.former_hours_per_period, # Former hours in single period
|
||||
self.genesis_hours_per_period, # Hours in single period at genesis
|
||||
self.hours_per_period, # Hours in single period
|
||||
|
||||
# Coefficients
|
||||
|
@ -467,9 +467,9 @@ class EconomicsFactory:
|
|||
|
||||
# Staking Escrow
|
||||
staking_parameters = list(staking_agent.staking_parameters())
|
||||
former_seconds_per_period = staking_parameters.pop(0)
|
||||
genesis_seconds_per_period = staking_parameters.pop(0)
|
||||
seconds_per_period = staking_parameters.pop(0)
|
||||
staking_parameters.insert(6, former_seconds_per_period // 60 // 60) # former_hours_per_period
|
||||
staking_parameters.insert(6, genesis_seconds_per_period // 60 // 60) # genesis_hours_per_period
|
||||
staking_parameters.insert(7, seconds_per_period // 60 // 60) # hours_per_period
|
||||
minting_coefficient = staking_parameters[0]
|
||||
lock_duration_coefficient_2 = staking_parameters[2]
|
||||
|
|
|
@ -646,7 +646,7 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
parameter_signatures = (
|
||||
|
||||
# Period
|
||||
'formerSecondsPerPeriod', # Former seconds in single period
|
||||
'genesisSecondsPerPeriod', # Seconds in single period at genesis
|
||||
'secondsPerPeriod', # Seconds in single period
|
||||
|
||||
# Coefficients
|
||||
|
|
|
@ -570,7 +570,7 @@ class StakingEscrowDeployer(BaseContractDeployer, UpgradeableContractMixin, Owna
|
|||
confirmations: int = 0,
|
||||
**overrides):
|
||||
constructor_kwargs = {
|
||||
"_formerHoursPerPeriod": self.economics.former_hours_per_period,
|
||||
"_genesisHoursPerPeriod": self.economics.genesis_hours_per_period,
|
||||
"_hoursPerPeriod": self.economics.hours_per_period,
|
||||
"_minLockedPeriods": self.economics.minimum_locked_periods,
|
||||
"_minAllowableLockedTokens": self.economics.minimum_allowed_locked,
|
||||
|
@ -599,7 +599,7 @@ class StakingEscrowDeployer(BaseContractDeployer, UpgradeableContractMixin, Owna
|
|||
**overrides):
|
||||
args = self.economics.staking_deployment_parameters
|
||||
constructor_kwargs = {
|
||||
"_formerHoursPerPeriod": args[0],
|
||||
"_genesisHoursPerPeriod": args[0],
|
||||
"_hoursPerPeriod": args[1],
|
||||
"_issuanceDecayCoefficient": args[2],
|
||||
"_lockDurationCoefficient1": args[3],
|
||||
|
|
|
@ -35,7 +35,7 @@ abstract contract Issuer is Upgradeable {
|
|||
// k2
|
||||
uint256 public immutable lockDurationCoefficient2;
|
||||
|
||||
uint32 public immutable formerSecondsPerPeriod;
|
||||
uint32 public immutable genesisSecondsPerPeriod;
|
||||
uint32 public immutable secondsPerPeriod;
|
||||
|
||||
// kmax
|
||||
|
@ -62,7 +62,7 @@ abstract contract Issuer is Upgradeable {
|
|||
(totalSupply - currentSupply) / d * (lockedValue / totalLockedValue) * (k1 + min(allLockedPeriods, kmax)) / k2
|
||||
if allLockedPeriods > maximumRewardedPeriods then allLockedPeriods = maximumRewardedPeriods
|
||||
* @param _token Token contract
|
||||
* @param _formerHoursPerPeriod Former size of period in hours
|
||||
* @param _genesisHoursPerPeriod Size of period in hours at genesis
|
||||
* @param _hoursPerPeriod Size of period in hours
|
||||
* @param _issuanceDecayCoefficient (d) Coefficient which modifies the rate at which the maximum issuance decays,
|
||||
* only applicable to Phase 2. d = 365 * half-life / LOG2 where default half-life = 2.
|
||||
|
@ -85,7 +85,7 @@ abstract contract Issuer is Upgradeable {
|
|||
*/
|
||||
constructor(
|
||||
NuCypherToken _token,
|
||||
uint32 _formerHoursPerPeriod,
|
||||
uint32 _genesisHoursPerPeriod,
|
||||
uint32 _hoursPerPeriod,
|
||||
uint256 _issuanceDecayCoefficient,
|
||||
uint256 _lockDurationCoefficient1,
|
||||
|
@ -98,8 +98,8 @@ abstract contract Issuer is Upgradeable {
|
|||
require(localTotalSupply > 0 &&
|
||||
_issuanceDecayCoefficient != 0 &&
|
||||
_hoursPerPeriod != 0 &&
|
||||
_formerHoursPerPeriod != 0 &&
|
||||
_formerHoursPerPeriod <= _hoursPerPeriod &&
|
||||
_genesisHoursPerPeriod != 0 &&
|
||||
_genesisHoursPerPeriod <= _hoursPerPeriod &&
|
||||
_lockDurationCoefficient1 != 0 &&
|
||||
_lockDurationCoefficient2 != 0 &&
|
||||
_maximumRewardedPeriods != 0);
|
||||
|
@ -124,7 +124,7 @@ abstract contract Issuer is Upgradeable {
|
|||
|
||||
token = _token;
|
||||
secondsPerPeriod = _hoursPerPeriod.mul32(1 hours);
|
||||
formerSecondsPerPeriod = _formerHoursPerPeriod.mul32(1 hours);
|
||||
genesisSecondsPerPeriod = _genesisHoursPerPeriod.mul32(1 hours);
|
||||
lockDurationCoefficient1 = _lockDurationCoefficient1;
|
||||
lockDurationCoefficient2 = _lockDurationCoefficient2;
|
||||
maximumRewardedPeriods = _maximumRewardedPeriods;
|
||||
|
@ -158,7 +158,7 @@ abstract contract Issuer is Upgradeable {
|
|||
* @return Recalculate period value using new basis
|
||||
*/
|
||||
function recalculatePeriod(uint16 _period) internal view returns (uint16) {
|
||||
return uint16(uint256(_period) * formerSecondsPerPeriod / secondsPerPeriod);
|
||||
return uint16(uint256(_period) * genesisSecondsPerPeriod / secondsPerPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -110,7 +110,7 @@ contract PolicyManager is Upgradeable {
|
|||
int256 public constant DEFAULT_FEE_DELTA = int256((uint256(0) - 1) >> 1);
|
||||
|
||||
StakingEscrow public immutable escrow;
|
||||
uint32 public immutable formerSecondsPerPeriod;
|
||||
uint32 public immutable genesisSecondsPerPeriod;
|
||||
uint32 public immutable secondsPerPeriod;
|
||||
|
||||
mapping (bytes16 => Policy) public policies;
|
||||
|
@ -130,13 +130,13 @@ contract PolicyManager is Upgradeable {
|
|||
uint32 localSecondsPerPeriod = _escrowLibrary.secondsPerPeriod();
|
||||
require(localSecondsPerPeriod > 0);
|
||||
secondsPerPeriod = localSecondsPerPeriod;
|
||||
uint32 localFormerSecondsPerPeriod = _escrowLibrary.formerSecondsPerPeriod();
|
||||
require(localFormerSecondsPerPeriod > 0);
|
||||
formerSecondsPerPeriod = localFormerSecondsPerPeriod;
|
||||
uint32 localgenesisSecondsPerPeriod = _escrowLibrary.genesisSecondsPerPeriod();
|
||||
require(localgenesisSecondsPerPeriod > 0);
|
||||
genesisSecondsPerPeriod = localgenesisSecondsPerPeriod;
|
||||
// checks possible migration
|
||||
if (_escrowDispatcher != _escrowLibrary) {
|
||||
require(_escrowDispatcher.secondsPerPeriod() == localSecondsPerPeriod ||
|
||||
_escrowDispatcher.secondsPerPeriod() == localFormerSecondsPerPeriod);
|
||||
_escrowDispatcher.secondsPerPeriod() == localgenesisSecondsPerPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ contract PolicyManager is Upgradeable {
|
|||
* @return Recalculate period value using new basis
|
||||
*/
|
||||
function recalculatePeriod(uint16 _period) internal view returns (uint16) {
|
||||
return uint16(uint256(_period) * formerSecondsPerPeriod / secondsPerPeriod);
|
||||
return uint16(uint256(_period) * genesisSecondsPerPeriod / secondsPerPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,7 +51,7 @@ contract StakingEscrowStub is Upgradeable {
|
|||
using AdditionalMath for uint32;
|
||||
|
||||
NuCypherToken public immutable token;
|
||||
uint32 public immutable formerSecondsPerPeriod;
|
||||
uint32 public immutable genesisSecondsPerPeriod;
|
||||
uint32 public immutable secondsPerPeriod;
|
||||
uint16 public immutable minLockedPeriods;
|
||||
uint256 public immutable minAllowableLockedTokens;
|
||||
|
@ -60,7 +60,7 @@ contract StakingEscrowStub is Upgradeable {
|
|||
/**
|
||||
* @notice Predefines some variables for use when deploying other contracts
|
||||
* @param _token Token contract
|
||||
* @param _formerHoursPerPeriod Former size of period in hours
|
||||
* @param _genesisHoursPerPeriod Size of period in hours at genesis
|
||||
* @param _hoursPerPeriod Size of period in hours
|
||||
* @param _minLockedPeriods Min amount of periods during which tokens can be locked
|
||||
* @param _minAllowableLockedTokens Min amount of tokens that can be locked
|
||||
|
@ -68,7 +68,7 @@ contract StakingEscrowStub is Upgradeable {
|
|||
*/
|
||||
constructor(
|
||||
NuCypherToken _token,
|
||||
uint32 _formerHoursPerPeriod,
|
||||
uint32 _genesisHoursPerPeriod,
|
||||
uint32 _hoursPerPeriod,
|
||||
uint16 _minLockedPeriods,
|
||||
uint256 _minAllowableLockedTokens,
|
||||
|
@ -76,14 +76,14 @@ contract StakingEscrowStub is Upgradeable {
|
|||
) {
|
||||
require(_token.totalSupply() > 0 &&
|
||||
_hoursPerPeriod != 0 &&
|
||||
_formerHoursPerPeriod != 0 &&
|
||||
_formerHoursPerPeriod <= _hoursPerPeriod &&
|
||||
_genesisHoursPerPeriod != 0 &&
|
||||
_genesisHoursPerPeriod <= _hoursPerPeriod &&
|
||||
_minLockedPeriods > 1 &&
|
||||
_maxAllowableLockedTokens != 0);
|
||||
|
||||
token = _token;
|
||||
secondsPerPeriod = _hoursPerPeriod.mul32(1 hours);
|
||||
formerSecondsPerPeriod = _formerHoursPerPeriod.mul32(1 hours);
|
||||
genesisSecondsPerPeriod = _genesisHoursPerPeriod.mul32(1 hours);
|
||||
minLockedPeriods = _minLockedPeriods;
|
||||
minAllowableLockedTokens = _minAllowableLockedTokens;
|
||||
maxAllowableLockedTokens = _maxAllowableLockedTokens;
|
||||
|
@ -96,7 +96,7 @@ contract StakingEscrowStub is Upgradeable {
|
|||
// we have to use real values even though this is a stub
|
||||
require(address(delegateGet(_testTarget, this.token.selector)) == address(token));
|
||||
// TODO uncomment after merging this PR
|
||||
// require(uint32(delegateGet(_testTarget, this.formerSecondsPerPeriod.selector)) == formerSecondsPerPeriod);
|
||||
// require(uint32(delegateGet(_testTarget, this.genesisSecondsPerPeriod.selector)) == genesisSecondsPerPeriod);
|
||||
require(uint32(delegateGet(_testTarget, this.secondsPerPeriod.selector)) == secondsPerPeriod);
|
||||
require(uint16(delegateGet(_testTarget, this.minLockedPeriods.selector)) == minLockedPeriods);
|
||||
require(delegateGet(_testTarget, this.minAllowableLockedTokens.selector) == minAllowableLockedTokens);
|
||||
|
@ -309,7 +309,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
address[] public stakers;
|
||||
mapping (address => address) public stakerFromWorker;
|
||||
|
||||
mapping (uint16 => uint256) stub4; // former lockedPerPeriod
|
||||
mapping (uint16 => uint256) stub4; // former slot for lockedPerPeriod
|
||||
uint128[] public balanceHistory;
|
||||
|
||||
address stub1; // former slot for PolicyManager
|
||||
|
@ -329,7 +329,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
* @param _policyManager Policy Manager contract
|
||||
* @param _adjudicator Adjudicator contract
|
||||
* @param _workLock WorkLock contract. Zero address if there is no WorkLock
|
||||
* @param _formerHoursPerPeriod Former size of period in hours
|
||||
* @param _genesisHoursPerPeriod Size of period in hours at genesis
|
||||
* @param _hoursPerPeriod Size of period in hours
|
||||
* @param _issuanceDecayCoefficient (d) Coefficient which modifies the rate at which the maximum issuance decays,
|
||||
* only applicable to Phase 2. d = 365 * half-life / LOG2 where default half-life = 2.
|
||||
|
@ -359,7 +359,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
PolicyManagerInterface _policyManager,
|
||||
AdjudicatorInterface _adjudicator,
|
||||
WorkLockInterface _workLock,
|
||||
uint32 _formerHoursPerPeriod,
|
||||
uint32 _genesisHoursPerPeriod,
|
||||
uint32 _hoursPerPeriod,
|
||||
uint256 _issuanceDecayCoefficient,
|
||||
uint256 _lockDurationCoefficient1,
|
||||
|
@ -374,7 +374,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
)
|
||||
Issuer(
|
||||
_token,
|
||||
_formerHoursPerPeriod,
|
||||
_genesisHoursPerPeriod,
|
||||
_hoursPerPeriod,
|
||||
_issuanceDecayCoefficient,
|
||||
_lockDurationCoefficient1,
|
||||
|
@ -392,7 +392,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
minWorkerPeriods = _minWorkerPeriods;
|
||||
|
||||
require((_policyManager.secondsPerPeriod() == _hoursPerPeriod * (1 hours) ||
|
||||
_policyManager.secondsPerPeriod() == _formerHoursPerPeriod * (1 hours)) &&
|
||||
_policyManager.secondsPerPeriod() == _genesisHoursPerPeriod * (1 hours)) &&
|
||||
_adjudicator.rewardCoefficient() != 0 &&
|
||||
(address(_workLock) == address(0) || _workLock.token() == _token));
|
||||
policyManager = _policyManager;
|
||||
|
@ -1249,7 +1249,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
subStake.lastPeriod = recalculatePeriod(subStake.lastPeriod);
|
||||
subStake.unlockingDuration = 0;
|
||||
} else {
|
||||
uint16 oldCurrentPeriod = uint16(block.timestamp / formerSecondsPerPeriod);
|
||||
uint16 oldCurrentPeriod = uint16(block.timestamp / genesisSecondsPerPeriod);
|
||||
uint16 lastPeriod = recalculatePeriod(oldCurrentPeriod + subStake.unlockingDuration);
|
||||
subStake.unlockingDuration = lastPeriod - getCurrentPeriod();
|
||||
if (subStake.unlockingDuration == 0) {
|
||||
|
|
|
@ -38,7 +38,7 @@ def token_economics():
|
|||
lock_duration_coefficient_1=4,
|
||||
lock_duration_coefficient_2=8,
|
||||
maximum_rewarded_periods=4,
|
||||
former_hours_per_period=1,
|
||||
genesis_hours_per_period=1,
|
||||
hours_per_period=1,
|
||||
minimum_locked_periods=2,
|
||||
minimum_allowed_locked=100,
|
||||
|
|
|
@ -27,7 +27,7 @@ from nucypher.blockchain.eth.deployers import (StakingEscrowDeployer, PolicyMana
|
|||
|
||||
@pytest.fixture(scope="module")
|
||||
def new_token_economics(token_economics):
|
||||
economics = StandardTokenEconomics(former_hours_per_period=token_economics.hours_per_period,
|
||||
economics = StandardTokenEconomics(genesis_hours_per_period=token_economics.hours_per_period,
|
||||
hours_per_period=2 * token_economics.hours_per_period)
|
||||
return economics
|
||||
|
||||
|
@ -63,7 +63,7 @@ def test_staking_escrow_preparation(testerchain,
|
|||
# Data is still old, because there is no upgrade yet
|
||||
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry)
|
||||
assert staking_agent.contract.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert staking_agent.contract.functions.formerSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert staking_agent.contract.functions.genesisSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
|
||||
|
||||
def test_policy_manager_preparation(testerchain,
|
||||
|
@ -75,7 +75,7 @@ def test_policy_manager_preparation(testerchain,
|
|||
# Data is still old, because there is no upgrade yet
|
||||
policy_manager_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=test_registry)
|
||||
assert policy_manager_agent.contract.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert policy_manager_agent.contract.functions.formerSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert policy_manager_agent.contract.functions.genesisSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
|
||||
|
||||
def test_staking_escrow_migration_upgrade(testerchain,
|
||||
|
@ -92,7 +92,7 @@ def test_staking_escrow_migration_upgrade(testerchain,
|
|||
# Now data must be new
|
||||
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry)
|
||||
assert staking_agent.contract.functions.secondsPerPeriod().call() == new_token_economics.seconds_per_period
|
||||
assert staking_agent.contract.functions.formerSecondsPerPeriod().call() == new_token_economics.former_seconds_per_period
|
||||
assert staking_agent.contract.functions.genesisSecondsPerPeriod().call() == new_token_economics.genesis_seconds_per_period
|
||||
|
||||
|
||||
def test_policy_manager_migration_upgrade(testerchain,
|
||||
|
@ -109,4 +109,4 @@ def test_policy_manager_migration_upgrade(testerchain,
|
|||
# Now data must be new
|
||||
policy_manager_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=test_registry)
|
||||
assert policy_manager_agent.contract.functions.secondsPerPeriod().call() == new_token_economics.seconds_per_period
|
||||
assert policy_manager_agent.contract.functions.formerSecondsPerPeriod().call() == new_token_economics.former_seconds_per_period
|
||||
assert policy_manager_agent.contract.functions.genesisSecondsPerPeriod().call() == new_token_economics.genesis_seconds_per_period
|
||||
|
|
|
@ -41,7 +41,7 @@ def test_issuer(testerchain, token, deploy_contract):
|
|||
lock_duration_coefficient_1=10 ** 4,
|
||||
lock_duration_coefficient_2=2 * 10 ** 4,
|
||||
maximum_rewarded_periods=10 ** 4,
|
||||
former_hours_per_period=1,
|
||||
genesis_hours_per_period=1,
|
||||
hours_per_period=1)
|
||||
|
||||
def calculate_first_phase_reward(locked, total_locked, locked_periods):
|
||||
|
@ -60,7 +60,7 @@ def test_issuer(testerchain, token, deploy_contract):
|
|||
|
||||
# Only token contract is allowed in Issuer constructor
|
||||
bad_args = dict(_token=staker,
|
||||
_formerHoursPerPeriod=economics.former_hours_per_period,
|
||||
_genesisHoursPerPeriod=economics.genesis_hours_per_period,
|
||||
_hoursPerPeriod=economics.hours_per_period,
|
||||
_issuanceDecayCoefficient=economics.issuance_decay_coefficient,
|
||||
_lockDurationCoefficient1=economics.lock_duration_coefficient_1,
|
||||
|
@ -204,7 +204,7 @@ def test_issuance_first_phase(testerchain, token, deploy_contract):
|
|||
lock_duration_coefficient_1=1,
|
||||
lock_duration_coefficient_2=2,
|
||||
maximum_rewarded_periods=1,
|
||||
former_hours_per_period=1,
|
||||
genesis_hours_per_period=1,
|
||||
hours_per_period=1)
|
||||
|
||||
creator = testerchain.client.accounts[0]
|
||||
|
@ -213,7 +213,7 @@ def test_issuance_first_phase(testerchain, token, deploy_contract):
|
|||
# Creator deploys the contract
|
||||
issuer, _ = deploy_contract(contract_name='IssuerMock',
|
||||
_token=token.address,
|
||||
_formerHoursPerPeriod=economics.former_hours_per_period,
|
||||
_genesisHoursPerPeriod=economics.genesis_hours_per_period,
|
||||
_hoursPerPeriod=economics.hours_per_period,
|
||||
_issuanceDecayCoefficient=economics.issuance_decay_coefficient,
|
||||
_lockDurationCoefficient1=economics.lock_duration_coefficient_1,
|
||||
|
@ -309,7 +309,7 @@ def test_issuance_second_phase(testerchain, token, deploy_contract):
|
|||
lock_duration_coefficient_1=1,
|
||||
lock_duration_coefficient_2=2,
|
||||
maximum_rewarded_periods=1,
|
||||
former_hours_per_period=1,
|
||||
genesis_hours_per_period=1,
|
||||
hours_per_period=1)
|
||||
|
||||
creator = testerchain.client.accounts[0]
|
||||
|
@ -318,7 +318,7 @@ def test_issuance_second_phase(testerchain, token, deploy_contract):
|
|||
# Creator deploys the contract
|
||||
issuer, _ = deploy_contract(contract_name='IssuerMock',
|
||||
_token=token.address,
|
||||
_formerHoursPerPeriod=economics.former_hours_per_period,
|
||||
_genesisHoursPerPeriod=economics.genesis_hours_per_period,
|
||||
_hoursPerPeriod=economics.hours_per_period,
|
||||
_issuanceDecayCoefficient=economics.issuance_decay_coefficient,
|
||||
_lockDurationCoefficient1=economics.lock_duration_coefficient_1,
|
||||
|
@ -398,7 +398,7 @@ def test_upgrading(testerchain, token, deploy_contract):
|
|||
contract_library_v1, _ = deploy_contract(
|
||||
contract_name='IssuerMock',
|
||||
_token=token.address,
|
||||
_formerHoursPerPeriod=1,
|
||||
_genesisHoursPerPeriod=1,
|
||||
_hoursPerPeriod=1,
|
||||
_issuanceDecayCoefficient=1,
|
||||
_lockDurationCoefficient1=1,
|
||||
|
@ -413,7 +413,7 @@ def test_upgrading(testerchain, token, deploy_contract):
|
|||
contract_library_v2, _ = deploy_contract(
|
||||
contract_name='IssuerV2Mock',
|
||||
_token=token.address,
|
||||
_formerHoursPerPeriod=2,
|
||||
_genesisHoursPerPeriod=2,
|
||||
_hoursPerPeriod=2,
|
||||
_issuanceDecayCoefficient=2,
|
||||
_lockDurationCoefficient1=2,
|
||||
|
@ -449,7 +449,7 @@ def test_upgrading(testerchain, token, deploy_contract):
|
|||
assert contract_library_v2.address == dispatcher.functions.target().call()
|
||||
assert 8 == contract.functions.mintingCoefficient().call()
|
||||
assert 2 * 3600 == contract.functions.secondsPerPeriod().call()
|
||||
assert 2 * 3600 == contract.functions.formerSecondsPerPeriod().call()
|
||||
assert 2 * 3600 == contract.functions.genesisSecondsPerPeriod().call()
|
||||
assert 2 == contract.functions.lockDurationCoefficient1().call()
|
||||
assert 4 == contract.functions.lockDurationCoefficient2().call()
|
||||
assert 2 == contract.functions.maximumRewardedPeriods().call()
|
||||
|
@ -466,7 +466,7 @@ def test_upgrading(testerchain, token, deploy_contract):
|
|||
contract_library_bad, _ = deploy_contract(
|
||||
contract_name='IssuerBad',
|
||||
_token=token.address,
|
||||
_formerHoursPerPeriod=2,
|
||||
_genesisHoursPerPeriod=2,
|
||||
_hoursPerPeriod=2,
|
||||
_issuanceDecayCoefficient=2,
|
||||
_lockDurationCoefficient1=2,
|
||||
|
@ -489,7 +489,7 @@ def test_upgrading(testerchain, token, deploy_contract):
|
|||
assert contract_library_v1.address == dispatcher.functions.target().call()
|
||||
assert 2 == contract.functions.mintingCoefficient().call()
|
||||
assert 3600 == contract.functions.secondsPerPeriod().call()
|
||||
assert 3600 == contract.functions.formerSecondsPerPeriod().call()
|
||||
assert 3600 == contract.functions.genesisSecondsPerPeriod().call()
|
||||
assert 1 == contract.functions.lockDurationCoefficient1().call()
|
||||
assert 2 == contract.functions.lockDurationCoefficient2().call()
|
||||
assert 1 == contract.functions.maximumRewardedPeriods().call()
|
||||
|
|
|
@ -15,7 +15,7 @@ contract IssuerMock is Issuer {
|
|||
|
||||
constructor(
|
||||
NuCypherToken _token,
|
||||
uint32 _formerHoursPerPeriod,
|
||||
uint32 _genesisHoursPerPeriod,
|
||||
uint32 _hoursPerPeriod,
|
||||
uint256 _issuanceDecayCoefficient,
|
||||
uint256 _lockDurationCoefficient1,
|
||||
|
@ -26,7 +26,7 @@ contract IssuerMock is Issuer {
|
|||
)
|
||||
Issuer(
|
||||
_token,
|
||||
_formerHoursPerPeriod,
|
||||
_genesisHoursPerPeriod,
|
||||
_hoursPerPeriod,
|
||||
_issuanceDecayCoefficient,
|
||||
_lockDurationCoefficient1,
|
||||
|
@ -78,7 +78,7 @@ contract IssuerV2Mock is Issuer {
|
|||
|
||||
constructor(
|
||||
NuCypherToken _token,
|
||||
uint32 _formerHoursPerPeriod,
|
||||
uint32 _genesisHoursPerPeriod,
|
||||
uint32 _hoursPerPeriod,
|
||||
uint256 _issuanceDecayCoefficient,
|
||||
uint256 _lockDurationCoefficient1,
|
||||
|
@ -89,7 +89,7 @@ contract IssuerV2Mock is Issuer {
|
|||
)
|
||||
Issuer(
|
||||
_token,
|
||||
_formerHoursPerPeriod,
|
||||
_genesisHoursPerPeriod,
|
||||
_hoursPerPeriod,
|
||||
_issuanceDecayCoefficient,
|
||||
_lockDurationCoefficient1,
|
||||
|
|
|
@ -51,7 +51,7 @@ contract StakingEscrowForPolicyMock {
|
|||
uint16 endPeriod;
|
||||
}
|
||||
|
||||
uint32 public immutable formerSecondsPerPeriod;
|
||||
uint32 public immutable genesisSecondsPerPeriod;
|
||||
uint32 public immutable secondsPerPeriod;
|
||||
|
||||
PolicyManager public policyManager;
|
||||
|
@ -59,12 +59,12 @@ contract StakingEscrowForPolicyMock {
|
|||
Downtime[] public downtime;
|
||||
|
||||
/**
|
||||
* @param _formerHoursPerPeriod Former size of period in hours
|
||||
* @param _genesisHoursPerPeriod Size of period in hours at genesis
|
||||
* @param _hoursPerPeriod Size of period in hours
|
||||
*/
|
||||
constructor(uint16 _formerHoursPerPeriod, uint16 _hoursPerPeriod) {
|
||||
constructor(uint16 _genesisHoursPerPeriod, uint16 _hoursPerPeriod) {
|
||||
secondsPerPeriod = _hoursPerPeriod * uint32(1 hours);
|
||||
formerSecondsPerPeriod = _formerHoursPerPeriod * uint32(1 hours);
|
||||
genesisSecondsPerPeriod = _genesisHoursPerPeriod * uint32(1 hours);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@ contract EnhancedStakingEscrow is StakingEscrow {
|
|||
PolicyManagerInterface _policyManager,
|
||||
AdjudicatorInterface _adjudicator,
|
||||
WorkLockInterface _workLock,
|
||||
uint32 _formerHoursPerPeriod,
|
||||
uint32 _genesisHoursPerPeriod,
|
||||
uint32 _hoursPerPeriod,
|
||||
uint256 _issuanceDecayCoefficient,
|
||||
uint256 _lockDurationCoefficient1,
|
||||
|
@ -35,7 +35,7 @@ contract EnhancedStakingEscrow is StakingEscrow {
|
|||
_policyManager,
|
||||
_adjudicator,
|
||||
_workLock,
|
||||
_formerHoursPerPeriod,
|
||||
_genesisHoursPerPeriod,
|
||||
_hoursPerPeriod,
|
||||
_issuanceDecayCoefficient,
|
||||
_lockDurationCoefficient1,
|
||||
|
@ -79,7 +79,7 @@ contract StakingEscrowBad is StakingEscrow {
|
|||
PolicyManagerInterface _policyManager,
|
||||
AdjudicatorInterface _adjudicator,
|
||||
WorkLockInterface _workLock,
|
||||
uint32 _formerHoursPerPeriod,
|
||||
uint32 _genesisHoursPerPeriod,
|
||||
uint32 _hoursPerPeriod,
|
||||
uint256 _issuanceDecayCoefficient,
|
||||
uint256 _lockDurationCoefficient1,
|
||||
|
@ -97,7 +97,7 @@ contract StakingEscrowBad is StakingEscrow {
|
|||
_policyManager,
|
||||
_adjudicator,
|
||||
_workLock,
|
||||
_formerHoursPerPeriod,
|
||||
_genesisHoursPerPeriod,
|
||||
_hoursPerPeriod,
|
||||
_issuanceDecayCoefficient,
|
||||
_lockDurationCoefficient1,
|
||||
|
@ -130,7 +130,7 @@ contract StakingEscrowV2Mock is StakingEscrow {
|
|||
PolicyManagerInterface _policyManager,
|
||||
AdjudicatorInterface _adjudicator,
|
||||
WorkLockInterface _workLock,
|
||||
uint32 _formerHoursPerPeriod,
|
||||
uint32 _genesisHoursPerPeriod,
|
||||
uint32 _hoursPerPeriod,
|
||||
uint256 _issuanceDecayCoefficient,
|
||||
uint256 _lockDurationCoefficient1,
|
||||
|
@ -148,7 +148,7 @@ contract StakingEscrowV2Mock is StakingEscrow {
|
|||
_policyManager,
|
||||
_adjudicator,
|
||||
_workLock,
|
||||
_formerHoursPerPeriod,
|
||||
_genesisHoursPerPeriod,
|
||||
_hoursPerPeriod,
|
||||
_issuanceDecayCoefficient,
|
||||
_lockDurationCoefficient1,
|
||||
|
|
|
@ -52,7 +52,7 @@ def token_economics():
|
|||
lock_duration_coefficient_1=4,
|
||||
lock_duration_coefficient_2=8,
|
||||
maximum_rewarded_periods=4,
|
||||
former_hours_per_period=1,
|
||||
genesis_hours_per_period=1,
|
||||
hours_per_period=1,
|
||||
minimum_locked_periods=6,
|
||||
minimum_allowed_locked=200,
|
||||
|
@ -74,7 +74,7 @@ def token(token_economics, deploy_contract):
|
|||
def escrow_dispatcher(testerchain, token, token_economics, deploy_contract):
|
||||
escrow_stub, _ = deploy_contract('StakingEscrowStub',
|
||||
token.address,
|
||||
token_economics.former_hours_per_period,
|
||||
token_economics.genesis_hours_per_period,
|
||||
token_economics.hours_per_period,
|
||||
token_economics.minimum_locked_periods,
|
||||
token_economics.minimum_allowed_locked,
|
||||
|
|
|
@ -34,7 +34,7 @@ def token_economics():
|
|||
lock_duration_coefficient_1=4,
|
||||
lock_duration_coefficient_2=8,
|
||||
maximum_rewarded_periods=4,
|
||||
former_hours_per_period=1,
|
||||
genesis_hours_per_period=1,
|
||||
hours_per_period=1,
|
||||
minimum_locked_periods=2,
|
||||
minimum_allowed_locked=100,
|
||||
|
|
|
@ -54,7 +54,7 @@ def test_upgrading(testerchain, token, token_economics, deploy_contract):
|
|||
contract_library_v2, _ = deploy_contract(
|
||||
contract_name='StakingEscrowV2Mock',
|
||||
_token=token.address,
|
||||
_formerHoursPerPeriod=token_economics.former_hours_per_period,
|
||||
_genesisHoursPerPeriod=token_economics.genesis_hours_per_period,
|
||||
_hoursPerPeriod=token_economics.hours_per_period,
|
||||
_issuanceDecayCoefficient=2,
|
||||
_lockDurationCoefficient1=2,
|
||||
|
@ -127,7 +127,7 @@ def test_upgrading(testerchain, token, token_economics, deploy_contract):
|
|||
contract_library_bad, _ = deploy_contract(
|
||||
contract_name='StakingEscrowBad',
|
||||
_token=token.address,
|
||||
_formerHoursPerPeriod=token_economics.former_hours_per_period,
|
||||
_genesisHoursPerPeriod=token_economics.genesis_hours_per_period,
|
||||
_hoursPerPeriod=token_economics.hours_per_period,
|
||||
_issuanceDecayCoefficient=2,
|
||||
_lockDurationCoefficient1=2,
|
||||
|
|
|
@ -22,7 +22,7 @@ from nucypher.blockchain.economics import StandardTokenEconomics
|
|||
|
||||
@pytest.fixture()
|
||||
def token_economics():
|
||||
economics = StandardTokenEconomics(former_hours_per_period=24,
|
||||
economics = StandardTokenEconomics(genesis_hours_per_period=24,
|
||||
hours_per_period=48,
|
||||
minimum_locked_periods=2)
|
||||
return economics
|
||||
|
|
|
@ -58,7 +58,7 @@ def test_intercontract_migration(testerchain, token_economics, token, deploy_con
|
|||
abi=escrow_old_library.abi,
|
||||
address=escrow_dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
assert escrow.functions.secondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert escrow.functions.secondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
|
||||
# Deploy old PolicyManager contract
|
||||
policy_manager_old_library, _ = deploy_contract(contract_name='PolicyManagerOld', _escrow=escrow.address)
|
||||
|
@ -68,7 +68,7 @@ def test_intercontract_migration(testerchain, token_economics, token, deploy_con
|
|||
abi=policy_manager_old_library.abi,
|
||||
address=policy_manager_dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
assert policy_manager.functions.secondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert policy_manager.functions.secondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
|
||||
tx = adjudicator.functions.setStakingEscrow(escrow.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
@ -82,10 +82,10 @@ def test_intercontract_migration(testerchain, token_economics, token, deploy_con
|
|||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert escrow.functions.getCurrentPeriod().call() == current_period + 1
|
||||
assert policy_manager.functions.getCurrentPeriod().call() == current_period + 1
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert escrow.functions.getCurrentPeriod().call() == current_period + 2
|
||||
assert policy_manager.functions.getCurrentPeriod().call() == current_period + 2
|
||||
|
||||
|
@ -105,7 +105,7 @@ def test_intercontract_migration(testerchain, token_economics, token, deploy_con
|
|||
|
||||
first_period = escrow.functions.getCurrentPeriod().call()
|
||||
if first_period % 2 == 1:
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.former_seconds_per_period)
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.genesis_seconds_per_period)
|
||||
first_period = escrow.functions.getCurrentPeriod().call()
|
||||
|
||||
# First staker: unlocked tokens, minted everything, withdrew everything, cleaned data
|
||||
|
@ -132,12 +132,12 @@ def test_intercontract_migration(testerchain, token_economics, token, deploy_con
|
|||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.former_seconds_per_period)
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.genesis_seconds_per_period)
|
||||
|
||||
# Create policies before migration
|
||||
policy_first_period = policy_manager.functions.getCurrentPeriod().call()
|
||||
policy_id = os.urandom(POLICY_ID_LENGTH)
|
||||
one_period = token_economics.former_seconds_per_period
|
||||
one_period = token_economics.genesis_seconds_per_period
|
||||
rate = 100
|
||||
current_timestamp = testerchain.w3.eth.getBlock('latest').timestamp
|
||||
end_timestamp = current_timestamp + (duration - 1) * one_period
|
||||
|
@ -154,12 +154,12 @@ def test_intercontract_migration(testerchain, token_economics, token, deploy_con
|
|||
for i in range(duration):
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.former_seconds_per_period)
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.genesis_seconds_per_period)
|
||||
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
|
||||
# Create policies to show refund and revoke before migration
|
||||
|
@ -267,10 +267,10 @@ def test_intercontract_migration(testerchain, token_economics, token, deploy_con
|
|||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert escrow.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert escrow.functions.formerSecondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert escrow.functions.genesisSecondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
assert escrow.functions.getCurrentPeriod().call() == current_period // 2
|
||||
assert policy_manager.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert policy_manager.functions.formerSecondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert policy_manager.functions.genesisSecondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
assert policy_manager.functions.getCurrentPeriod().call() == current_period // 2
|
||||
|
||||
reset_timestamp = testerchain.w3.eth.getBlock('latest').timestamp
|
||||
|
@ -492,10 +492,10 @@ def test_intercontract_migration(testerchain, token_economics, token, deploy_con
|
|||
# Time machine test
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.seconds_per_period)
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert escrow.functions.getCurrentPeriod().call() == current_period
|
||||
assert policy_manager.functions.getCurrentPeriod().call() == current_period
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert escrow.functions.getCurrentPeriod().call() == current_period + 1
|
||||
assert policy_manager.functions.getCurrentPeriod().call() == current_period + 1
|
||||
testerchain.time_travel(hours=token_economics.hours_per_period)
|
||||
|
@ -507,13 +507,13 @@ def test_intercontract_migration(testerchain, token_economics, token, deploy_con
|
|||
##########
|
||||
tx = escrow_dispatcher.functions.upgrade(escrow_library.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert escrow.functions.formerSecondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert escrow.functions.genesisSecondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
assert escrow.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
|
||||
tx = policy_manager_dispatcher.functions.upgrade(policy_manager_library.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert policy_manager.functions.resetTimestamp().call() == reset_timestamp
|
||||
assert policy_manager.functions.formerSecondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert policy_manager.functions.genesisSecondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
assert policy_manager.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
|
||||
deploy_args = token_economics.staking_deployment_parameters
|
||||
|
@ -537,10 +537,10 @@ def test_intercontract_migration(testerchain, token_economics, token, deploy_con
|
|||
tx = policy_manager_dispatcher.functions.upgrade(policy_manager_2_library.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert escrow.functions.formerSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert escrow.functions.genesisSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert escrow.functions.secondsPerPeriod().call() == 2 * token_economics.seconds_per_period
|
||||
assert escrow.functions.getCurrentPeriod().call() == current_period // 2
|
||||
assert policy_manager.functions.resetTimestamp().call() == reset_timestamp
|
||||
assert policy_manager.functions.formerSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert policy_manager.functions.genesisSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert policy_manager.functions.secondsPerPeriod().call() == 2 * token_economics.seconds_per_period
|
||||
assert policy_manager.functions.getCurrentPeriod().call() == current_period // 2
|
||||
|
|
|
@ -28,7 +28,7 @@ def test_issuer_migration(testerchain, token, token_economics, deploy_contract):
|
|||
issuer_old_library, _ = deploy_contract(
|
||||
contract_name='IssuerOldMock',
|
||||
_token=token.address,
|
||||
_hoursPerPeriod=token_economics.former_hours_per_period,
|
||||
_hoursPerPeriod=token_economics.genesis_hours_per_period,
|
||||
_issuanceDecayCoefficient=int(token_economics.issuance_decay_coefficient),
|
||||
_lockDurationCoefficient1=int(token_economics.lock_duration_coefficient_1),
|
||||
_lockDurationCoefficient2=int(token_economics.lock_duration_coefficient_2),
|
||||
|
@ -42,10 +42,10 @@ def test_issuer_migration(testerchain, token, token_economics, deploy_contract):
|
|||
abi=issuer_old_library.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
|
||||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 1
|
||||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
current_minting_period = current_period
|
||||
|
@ -63,8 +63,8 @@ def test_issuer_migration(testerchain, token, token_economics, deploy_contract):
|
|||
deploy_contract(
|
||||
contract_name='IssuerMock',
|
||||
_token=token.address,
|
||||
_formerHoursPerPeriod=token_economics.hours_per_period,
|
||||
_hoursPerPeriod=token_economics.former_hours_per_period,
|
||||
_genesisHoursPerPeriod=token_economics.hours_per_period,
|
||||
_hoursPerPeriod=token_economics.genesis_hours_per_period,
|
||||
_issuanceDecayCoefficient=int(token_economics.issuance_decay_coefficient),
|
||||
_lockDurationCoefficient1=int(token_economics.lock_duration_coefficient_1),
|
||||
_lockDurationCoefficient2=int(token_economics.lock_duration_coefficient_2),
|
||||
|
@ -77,7 +77,7 @@ def test_issuer_migration(testerchain, token, token_economics, deploy_contract):
|
|||
issuer_library, _ = deploy_contract(
|
||||
contract_name='IssuerMock',
|
||||
_token=token.address,
|
||||
_formerHoursPerPeriod=token_economics.former_hours_per_period,
|
||||
_genesisHoursPerPeriod=token_economics.genesis_hours_per_period,
|
||||
_hoursPerPeriod=token_economics.hours_per_period,
|
||||
_issuanceDecayCoefficient=int(token_economics.issuance_decay_coefficient),
|
||||
_lockDurationCoefficient1=int(token_economics.lock_duration_coefficient_1),
|
||||
|
@ -94,7 +94,7 @@ def test_issuer_migration(testerchain, token, token_economics, deploy_contract):
|
|||
tx = dispatcher.functions.upgrade(issuer_library.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert contract.functions.formerSecondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert contract.functions.genesisSecondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period // 2
|
||||
assert contract.functions.currentMintingPeriod().call() == current_minting_period // 2
|
||||
|
||||
|
@ -104,9 +104,9 @@ def test_issuer_migration(testerchain, token, token_economics, deploy_contract):
|
|||
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.seconds_per_period)
|
||||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 1
|
||||
testerchain.time_travel(hours=token_economics.hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 2
|
||||
|
@ -116,7 +116,7 @@ def test_issuer_migration(testerchain, token, token_economics, deploy_contract):
|
|||
issuer_library_2, _ = deploy_contract(
|
||||
contract_name='IssuerMock',
|
||||
_token=token.address,
|
||||
_formerHoursPerPeriod=token_economics.hours_per_period,
|
||||
_genesisHoursPerPeriod=token_economics.hours_per_period,
|
||||
_hoursPerPeriod=2 * token_economics.hours_per_period,
|
||||
_issuanceDecayCoefficient=int(token_economics.issuance_decay_coefficient),
|
||||
_lockDurationCoefficient1=int(token_economics.lock_duration_coefficient_1),
|
||||
|
@ -128,7 +128,7 @@ def test_issuer_migration(testerchain, token, token_economics, deploy_contract):
|
|||
|
||||
tx = dispatcher.functions.upgrade(issuer_library_2.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract.functions.formerSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert contract.functions.genesisSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert contract.functions.secondsPerPeriod().call() == 2 * token_economics.seconds_per_period
|
||||
assert contract.functions.getCurrentPeriod().call() == (current_period + 2) // 2
|
||||
assert contract.functions.currentMintingPeriod().call() == current_minting_period // 4
|
||||
|
|
|
@ -39,8 +39,8 @@ def test_policy_manager_migration(testerchain, token_economics, deploy_contract)
|
|||
# Deploy StakingEscrow mock
|
||||
escrow, _ = deploy_contract(
|
||||
contract_name='StakingEscrowForPolicyMock',
|
||||
_formerHoursPerPeriod=token_economics.former_hours_per_period,
|
||||
_hoursPerPeriod=token_economics.former_hours_per_period
|
||||
_genesisHoursPerPeriod=token_economics.genesis_hours_per_period,
|
||||
_hoursPerPeriod=token_economics.genesis_hours_per_period
|
||||
)
|
||||
|
||||
# Deploy old contract
|
||||
|
@ -51,12 +51,12 @@ def test_policy_manager_migration(testerchain, token_economics, deploy_contract)
|
|||
abi=policy_manager_old_library.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
|
||||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 1
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 2
|
||||
|
||||
# Register some nodes
|
||||
|
@ -74,7 +74,7 @@ def test_policy_manager_migration(testerchain, token_economics, deploy_contract)
|
|||
# Create policies before migration
|
||||
policy_id = os.urandom(POLICY_ID_LENGTH)
|
||||
number_of_periods = 10
|
||||
one_period = token_economics.former_seconds_per_period
|
||||
one_period = token_economics.genesis_seconds_per_period
|
||||
rate = 100
|
||||
value = number_of_periods * rate
|
||||
current_timestamp = testerchain.w3.eth.getBlock('latest').timestamp
|
||||
|
@ -83,11 +83,11 @@ def test_policy_manager_migration(testerchain, token_economics, deploy_contract)
|
|||
.transact({'from': alice, 'value': 3 * value, 'gas_price': 0})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
tx = escrow.functions.ping(node3, current_period - 1, 0, current_period + 1).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
tx = escrow.functions.ping(node3, current_period - 1, 0, current_period + 1).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
@ -136,7 +136,7 @@ def test_policy_manager_migration(testerchain, token_economics, deploy_contract)
|
|||
# Redeploy StakingEscrow mock
|
||||
escrow, _ = deploy_contract(
|
||||
contract_name='StakingEscrowForPolicyMock',
|
||||
_formerHoursPerPeriod=token_economics.former_hours_per_period,
|
||||
_genesisHoursPerPeriod=token_economics.genesis_hours_per_period,
|
||||
_hoursPerPeriod=token_economics.hours_per_period
|
||||
)
|
||||
tx = escrow.functions.setPolicyManager(dispatcher.address).transact()
|
||||
|
@ -154,7 +154,7 @@ def test_policy_manager_migration(testerchain, token_economics, deploy_contract)
|
|||
tx = dispatcher.functions.upgrade(policy_manager_library.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert contract.functions.formerSecondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert contract.functions.genesisSecondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period // 2
|
||||
assert policy_manager_library.functions.resetTimestamp().call() == 0
|
||||
reset_timestamp = testerchain.w3.eth.getBlock('latest').timestamp
|
||||
|
@ -187,9 +187,9 @@ def test_policy_manager_migration(testerchain, token_economics, deploy_contract)
|
|||
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.seconds_per_period)
|
||||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 1
|
||||
testerchain.time_travel(hours=token_economics.hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 2
|
||||
|
@ -300,12 +300,12 @@ def test_policy_manager_migration(testerchain, token_economics, deploy_contract)
|
|||
tx = dispatcher.functions.upgrade(policy_manager_library.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract.functions.resetTimestamp().call() == reset_timestamp
|
||||
assert contract.functions.formerSecondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert contract.functions.genesisSecondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
|
||||
escrow, _ = deploy_contract(
|
||||
contract_name='StakingEscrowForPolicyMock',
|
||||
_formerHoursPerPeriod=token_economics.hours_per_period,
|
||||
_genesisHoursPerPeriod=token_economics.hours_per_period,
|
||||
_hoursPerPeriod=2 * token_economics.hours_per_period
|
||||
)
|
||||
policy_manager_2_library, _ = deploy_contract(contract_name='PolicyManager',
|
||||
|
@ -315,6 +315,6 @@ def test_policy_manager_migration(testerchain, token_economics, deploy_contract)
|
|||
tx = dispatcher.functions.upgrade(policy_manager_2_library.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract.functions.resetTimestamp().call() == reset_timestamp
|
||||
assert contract.functions.formerSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert contract.functions.genesisSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert contract.functions.secondsPerPeriod().call() == 2 * token_economics.seconds_per_period
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period // 2
|
||||
|
|
|
@ -47,7 +47,7 @@ def test_staking_escrow_migration(testerchain, token_economics, token, deploy_co
|
|||
abi=staking_escrow_old_library.abi,
|
||||
address=dispatcher.address,
|
||||
ContractFactoryClass=Contract)
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
|
||||
tx = policy_manager.functions.setStakingEscrow(contract.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
@ -63,9 +63,9 @@ def test_staking_escrow_migration(testerchain, token_economics, token, deploy_co
|
|||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 1
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 2
|
||||
|
||||
# Initialize Escrow contract
|
||||
|
@ -85,7 +85,7 @@ def test_staking_escrow_migration(testerchain, token_economics, token, deploy_co
|
|||
|
||||
first_period = contract.functions.getCurrentPeriod().call()
|
||||
if first_period % 2 == 1:
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
first_period = contract.functions.getCurrentPeriod().call()
|
||||
|
||||
# First staker: unlocked tokens, minted everything, forgot to withdraw before migration
|
||||
|
@ -139,12 +139,12 @@ def test_staking_escrow_migration(testerchain, token_economics, token, deploy_co
|
|||
testerchain.wait_for_receipt(tx)
|
||||
tx = contract.functions.commitToNextPeriod().transact({'from': staker5})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
|
||||
tx = contract.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
|
||||
tx = contract.functions.mint().transact({'from': staker1})
|
||||
|
@ -216,7 +216,7 @@ def test_staking_escrow_migration(testerchain, token_economics, token, deploy_co
|
|||
tx = dispatcher.functions.upgrade(staking_escrow_library.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert contract.functions.formerSecondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert contract.functions.genesisSecondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period // 2
|
||||
assert contract.functions.lockedPerPeriod(current_period).call() == 0
|
||||
assert contract.functions.lockedPerPeriod(current_period - 1).call() == 0
|
||||
|
@ -534,9 +534,9 @@ def test_staking_escrow_migration(testerchain, token_economics, token, deploy_co
|
|||
# Time machine test
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.seconds_per_period)
|
||||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period
|
||||
testerchain.time_travel(hours=token_economics.former_hours_per_period)
|
||||
testerchain.time_travel(hours=token_economics.genesis_hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 1
|
||||
testerchain.time_travel(hours=token_economics.hours_per_period)
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period + 2
|
||||
|
@ -562,7 +562,7 @@ def test_staking_escrow_migration(testerchain, token_economics, token, deploy_co
|
|||
##########
|
||||
tx = dispatcher.functions.upgrade(staking_escrow_library.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract.functions.formerSecondsPerPeriod().call() == token_economics.former_seconds_per_period
|
||||
assert contract.functions.genesisSecondsPerPeriod().call() == token_economics.genesis_seconds_per_period
|
||||
assert contract.functions.secondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
|
||||
policy_manager, _ = deploy_contract(
|
||||
|
@ -582,6 +582,6 @@ def test_staking_escrow_migration(testerchain, token_economics, token, deploy_co
|
|||
current_period = contract.functions.getCurrentPeriod().call()
|
||||
tx = dispatcher.functions.upgrade(staking_escrow_2_library.address).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert contract.functions.formerSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert contract.functions.genesisSecondsPerPeriod().call() == token_economics.seconds_per_period
|
||||
assert contract.functions.secondsPerPeriod().call() == 2 * token_economics.seconds_per_period
|
||||
assert contract.functions.getCurrentPeriod().call() == current_period // 2
|
||||
|
|
|
@ -92,7 +92,7 @@ CONSTRUCTOR_OVERRIDES = {
|
|||
"_miningCoefficient": 2,
|
||||
"_lockedPeriodsCoefficient": 1,
|
||||
"_rewardedPeriods": 1},
|
||||
"v5.7.1": {"_formerHoursPerPeriod": None}
|
||||
"v5.7.1": {"_genesisHoursPerPeriod": None}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ def test_exact_economics():
|
|||
expected_phase2_coefficient
|
||||
|
||||
# After sanity checking, assemble expected test deployment parameters
|
||||
expected_deployment_parameters = (24, # Hours of former period duration
|
||||
expected_deployment_parameters = (24, # Hours in single period at genesis
|
||||
24, # Hours in single period
|
||||
1053, # Coefficient which modifies the rate at which the maximum issuance decays (d)
|
||||
365, # Numerator of the locking duration coefficient (k1)
|
||||
|
|
|
@ -606,7 +606,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
*args,
|
||||
**kwargs)
|
||||
|
||||
token_economics = StandardTokenEconomics(former_hours_per_period=StandardTokenEconomics._default_hours_per_period,
|
||||
token_economics = StandardTokenEconomics(genesis_hours_per_period=StandardTokenEconomics._default_hours_per_period,
|
||||
hours_per_period=2 * StandardTokenEconomics._default_hours_per_period)
|
||||
|
||||
token, _ = deploy_contract('NuCypherToken', _totalSupplyOfTokens=token_economics.erc20_total_supply)
|
||||
|
@ -687,7 +687,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker4})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.former_seconds_per_period)
|
||||
testerchain.time_travel(periods=1, periods_base=token_economics.genesis_seconds_per_period)
|
||||
|
||||
##########
|
||||
# Deploy new version of contracts
|
||||
|
|
Loading…
Reference in New Issue