mirror of https://github.com/nucypher/nucypher.git
Remove force re-stake lock
parent
c10b9665ce
commit
d51ad8db93
|
@ -408,7 +408,6 @@ class ContractAdministrator(NucypherTokenActor):
|
|||
|
||||
def batch_deposits(self,
|
||||
allocation_data_filepath: str,
|
||||
release_period: int,
|
||||
interactive: bool = True,
|
||||
emitter: StdoutEmitter = None,
|
||||
gas_limit: int = None
|
||||
|
@ -433,7 +432,7 @@ class ContractAdministrator(NucypherTokenActor):
|
|||
if interactive and not emitter:
|
||||
raise ValueError("'emitter' is a required keyword argument when interactive is True.")
|
||||
|
||||
allocator = Allocator(allocation_data_filepath, self.registry, self.deployer_address, release_period)
|
||||
allocator = Allocator(allocation_data_filepath, self.registry, self.deployer_address)
|
||||
|
||||
# TODO: Check validity of input address (check TX)
|
||||
|
||||
|
@ -533,7 +532,7 @@ class Allocator:
|
|||
|
||||
OCCUPATION_RATIO = 0.9 # When there's no explicit gas limit, we'll try to use the block limit up to this ratio
|
||||
|
||||
def __init__(self, filepath: str, registry, deployer_address, release_period):
|
||||
def __init__(self, filepath: str, registry, deployer_address):
|
||||
|
||||
self.log = Logger("allocator")
|
||||
self.staking_agent = ContractAgency.get_agent(StakingEscrowAgent,
|
||||
|
@ -542,7 +541,6 @@ class Allocator:
|
|||
self.allocations = dict()
|
||||
self.deposited = set()
|
||||
self.economics = EconomicsFactory.get_economics(registry)
|
||||
self.release_period = release_period
|
||||
|
||||
self.__total_to_allocate = 0
|
||||
self.__process_allocation_data(str(filepath))
|
||||
|
@ -633,7 +631,6 @@ class Allocator:
|
|||
batch_parameters = self.staking_agent.construct_batch_deposit_parameters(deposits=test_batch)
|
||||
try:
|
||||
estimated_gas = self.staking_agent.batch_deposit(*batch_parameters,
|
||||
release_period=self.release_period,
|
||||
sender_address=sender_address,
|
||||
dry_run=True,
|
||||
gas_limit=gas_limit)
|
||||
|
@ -652,7 +649,6 @@ class Allocator:
|
|||
|
||||
batch_parameters = self.staking_agent.construct_batch_deposit_parameters(deposits=last_good_batch)
|
||||
receipt = self.staking_agent.batch_deposit(*batch_parameters,
|
||||
release_period=self.release_period,
|
||||
sender_address=sender_address,
|
||||
gas_limit=gas_limit)
|
||||
|
||||
|
|
|
@ -484,7 +484,6 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
number_of_substakes: List[int],
|
||||
amounts: List[NuNits],
|
||||
lock_periods: List[PeriodDelta],
|
||||
release_period: Period,
|
||||
sender_address: ChecksumAddress,
|
||||
dry_run: bool = False,
|
||||
gas_limit: Optional[Wei] = None
|
||||
|
@ -495,7 +494,7 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
raise ValueError(f"{gas_limit} is not enough gas for any batch deposit")
|
||||
|
||||
contract_function: ContractFunction = self.contract.functions.batchDeposit(
|
||||
stakers, number_of_substakes, amounts, lock_periods, release_period)
|
||||
stakers, number_of_substakes, amounts, lock_periods)
|
||||
if dry_run:
|
||||
payload: TxParams = {'from': sender_address}
|
||||
if gas_limit:
|
||||
|
|
|
@ -41,7 +41,7 @@ interface WorkLockInterface {
|
|||
/**
|
||||
* @notice Contract holds and locks stakers tokens.
|
||||
* Each staker that locks their tokens will receive some compensation
|
||||
* @dev |v5.3.1|
|
||||
* @dev |v5.4.1|
|
||||
*/
|
||||
contract StakingEscrow is Issuer, IERC900History {
|
||||
|
||||
|
@ -530,36 +530,10 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
}
|
||||
|
||||
/**
|
||||
* @notice Enable `reStake` and lock this parameter even if parameter is locked
|
||||
* @param _staker Staker address
|
||||
* @param _info Staker structure
|
||||
* @param _lockReStakeUntilPeriod Can't change `reStake` value until this period
|
||||
*/
|
||||
function forceLockReStake(
|
||||
address _staker,
|
||||
StakerInfo storage _info,
|
||||
uint16 _lockReStakeUntilPeriod
|
||||
)
|
||||
internal
|
||||
{
|
||||
// reset bit when `reStake` is already disabled
|
||||
if (_info.flags.bitSet(RE_STAKE_DISABLED_INDEX) == true) {
|
||||
_info.flags = _info.flags.toggleBit(RE_STAKE_DISABLED_INDEX);
|
||||
emit ReStakeSet(_staker, true);
|
||||
}
|
||||
// lock `reStake` parameter if it's not locked or locked for too short duration
|
||||
if (_lockReStakeUntilPeriod > _info.lockReStakeUntilPeriod) {
|
||||
_info.lockReStakeUntilPeriod = _lockReStakeUntilPeriod;
|
||||
emit ReStakeLocked(_staker, _lockReStakeUntilPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Deposit tokens and lock `reStake` parameter from WorkLock contract
|
||||
* @notice Deposit tokens from WorkLock contract
|
||||
* @param _staker Staker address
|
||||
* @param _value Amount of tokens to deposit
|
||||
* @param _periods Amount of periods during which tokens will be locked
|
||||
* and number of period after which `reStake` can be changed
|
||||
*/
|
||||
function depositFromWorkLock(
|
||||
address _staker,
|
||||
|
@ -570,9 +544,6 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
{
|
||||
require(msg.sender == address(workLock));
|
||||
deposit(_staker, msg.sender, MAX_SUB_STAKES, _value, _periods);
|
||||
StakerInfo storage info = stakerInfo[_staker];
|
||||
uint16 lockReStakeUntilPeriod = getCurrentPeriod().add16(_periods).add16(1);
|
||||
forceLockReStake(_staker, info, lockReStakeUntilPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -661,18 +632,14 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
* @param _numberOfSubStakes Number of sub-stakes which belong to staker in _values and _periods arrays
|
||||
* @param _values Amount of tokens to deposit for each staker
|
||||
* @param _periods Amount of periods during which tokens will be locked for each staker
|
||||
* @param _lockReStakeUntilPeriod Can't change `reStake` value until this period. Zero value will disable locking
|
||||
*/
|
||||
function batchDeposit(
|
||||
address[] calldata _stakers,
|
||||
uint256[] calldata _numberOfSubStakes,
|
||||
uint256[] calldata _values,
|
||||
uint16[] calldata _periods,
|
||||
uint16 _lockReStakeUntilPeriod
|
||||
uint16[] calldata _periods
|
||||
)
|
||||
// `onlyOwner` modifier is for prevent malicious using of `forceLockReStake`
|
||||
// remove `onlyOwner` if `forceLockReStake` will be removed
|
||||
external onlyOwner
|
||||
external
|
||||
{
|
||||
uint256 subStakesLength = _values.length;
|
||||
require(_stakers.length != 0 &&
|
||||
|
@ -708,10 +675,6 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
}
|
||||
require(info.value <= maxAllowableLockedTokens);
|
||||
info.history.addSnapshot(info.value);
|
||||
|
||||
if (_lockReStakeUntilPeriod >= nextPeriod) {
|
||||
forceLockReStake(staker, info, _lockReStakeUntilPeriod);
|
||||
}
|
||||
}
|
||||
require(j == subStakesLength);
|
||||
uint256 lastGlobalBalance = uint256(balanceHistory.lastValue());
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
|
||||
|
@ -255,7 +257,7 @@ contract PoolingStakingContract is AbstractStakingContract, Ownable {
|
|||
/**
|
||||
* @notice Calling fallback function is allowed only for the owner
|
||||
**/
|
||||
function isFallbackAllowed() public override returns (bool) {
|
||||
function isFallbackAllowed() public view override returns (bool) {
|
||||
return msg.sender == owner();
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ from nucypher.cli.literature import (
|
|||
SUCCESSFUL_SAVE_DEPLOY_RECEIPTS,
|
||||
SUCCESSFUL_SAVE_MULTISIG_TX_PROPOSAL,
|
||||
SUCCESSFUL_UPGRADE,
|
||||
UNKNOWN_CONTRACT_NAME, PROMPT_FOR_RELEASE_PERIOD
|
||||
UNKNOWN_CONTRACT_NAME
|
||||
)
|
||||
from nucypher.cli.options import (
|
||||
group_options,
|
||||
|
@ -508,18 +508,14 @@ def contracts(general_config, actor_options, mode, activate, gas, ignore_deploye
|
|||
@group_general_config
|
||||
@group_actor_options
|
||||
@click.option('--allocation-infile', help="Input path for token allocation JSON file", type=EXISTING_READABLE_FILE)
|
||||
@click.option('--release-period', help="Period number when re-stake lock will be released", type=click.INT)
|
||||
@option_gas
|
||||
def allocations(general_config, actor_options, allocation_infile, gas, release_period):
|
||||
def allocations(general_config, actor_options, allocation_infile, gas):
|
||||
"""Deposit stake allocations in batches"""
|
||||
emitter = general_config.emitter
|
||||
ADMINISTRATOR, _, deployer_interface, local_registry = actor_options.create_actor(emitter)
|
||||
if not allocation_infile:
|
||||
allocation_infile = click.prompt(PROMPT_FOR_ALLOCATION_DATA_FILEPATH)
|
||||
if release_period is None:
|
||||
release_period = click.prompt(PROMPT_FOR_RELEASE_PERIOD)
|
||||
receipts = ADMINISTRATOR.batch_deposits(allocation_data_filepath=allocation_infile,
|
||||
release_period=release_period,
|
||||
emitter=emitter,
|
||||
gas_limit=gas,
|
||||
interactive=not actor_options.force)
|
||||
|
|
|
@ -411,8 +411,6 @@ DISPLAY_SENDER_TOKEN_BALANCE_BEFORE_TRANSFER = "Deployer NU balance: {token_bala
|
|||
|
||||
PROMPT_FOR_ALLOCATION_DATA_FILEPATH = "Enter allocations data filepath"
|
||||
|
||||
PROMPT_FOR_RELEASE_PERIOD = "Enter period number when re-stake lock should be released"
|
||||
|
||||
SUCCESSFUL_SAVE_BATCH_DEPOSIT_RECEIPTS = "Saved batch deposits receipts to {receipts_filepath}"
|
||||
|
||||
SUCCESSFUL_SAVE_DEPLOY_RECEIPTS = "Saved deployment receipts to {receipts_filepath}"
|
||||
|
|
|
@ -77,9 +77,7 @@ def test_rapid_deployment(token_economics, test_registry, tmpdir, get_random_che
|
|||
with open(filepath, 'w') as f:
|
||||
json.dump(allocation_data, f)
|
||||
|
||||
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry)
|
||||
current_period = staking_agent.get_current_period()
|
||||
administrator.batch_deposits(allocation_data_filepath=str(filepath), interactive=False, release_period=current_period+10)
|
||||
administrator.batch_deposits(allocation_data_filepath=str(filepath), interactive=False)
|
||||
|
||||
minimum, default, maximum = 10, 20, 30
|
||||
administrator.set_fee_rate_range(minimum, default, maximum)
|
||||
|
|
|
@ -473,18 +473,15 @@ def test_batch_deposit(testerchain,
|
|||
not_enough_gas = 800_000
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
staking_agent.batch_deposit(*batch_parameters,
|
||||
release_period=current_period + 2,
|
||||
sender_address=testerchain.etherbase_account,
|
||||
dry_run=True,
|
||||
gas_limit=not_enough_gas)
|
||||
|
||||
staking_agent.batch_deposit(*batch_parameters,
|
||||
release_period=current_period + 2,
|
||||
sender_address=testerchain.etherbase_account,
|
||||
dry_run=True)
|
||||
|
||||
staking_agent.batch_deposit(*batch_parameters,
|
||||
release_period=current_period + 2,
|
||||
sender_address=testerchain.etherbase_account)
|
||||
|
||||
for staker in stakers:
|
||||
|
@ -495,4 +492,3 @@ def test_batch_deposit(testerchain,
|
|||
first_period, last_period, locked_value = substake
|
||||
assert last_period == first_period + lock_periods - 1
|
||||
assert locked_value == amount
|
||||
assert staking_agent.is_restaking_locked(staker_address=staker)
|
||||
|
|
|
@ -214,9 +214,6 @@ def test_batch_deposits(click_runner,
|
|||
agency_local_registry,
|
||||
mock_allocation_infile,
|
||||
token_economics):
|
||||
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=agency_local_registry)
|
||||
current_period = staking_agent.get_current_period()
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
|
@ -224,7 +221,6 @@ def test_batch_deposits(click_runner,
|
|||
deploy_command = ('allocations',
|
||||
'--registry-infile', agency_local_registry.filepath,
|
||||
'--allocation-infile', mock_allocation_infile,
|
||||
'--release-period', current_period + 10,
|
||||
'--provider', TEST_PROVIDER_URI)
|
||||
|
||||
account_index = '0\n'
|
||||
|
|
|
@ -319,20 +319,12 @@ def test_batch_deposit(testerchain, token_economics, token, escrow, multisig):
|
|||
duration = token_economics.minimum_locked_periods
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
|
||||
# Only owner can use batch deposit
|
||||
tx = token.functions.approve(escrow.address, staker1_tokens).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit(
|
||||
[staker1], [1], [staker1_tokens], [duration], current_period + 1).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = token.functions.transfer(multisig.address, staker1_tokens).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.approve(escrow.address, staker1_tokens) \
|
||||
.buildTransaction({'from': multisig.address, 'gasPrice': 0})
|
||||
execute_multisig_transaction(testerchain, multisig, [contracts_owners[0], contracts_owners[1]], tx)
|
||||
tx = escrow.functions.batchDeposit([staker1], [1], [staker1_tokens], [duration], current_period + 1)\
|
||||
tx = escrow.functions.batchDeposit([staker1], [1], [staker1_tokens], [duration])\
|
||||
.buildTransaction({'from': multisig.address, 'gasPrice': 0})
|
||||
execute_multisig_transaction(testerchain, multisig, [contracts_owners[0], contracts_owners[1]], tx)
|
||||
|
||||
|
@ -344,10 +336,6 @@ def test_batch_deposit(testerchain, token_economics, token, escrow, multisig):
|
|||
assert escrow.functions.getLockedTokens(staker1, duration).call() == staker1_tokens
|
||||
assert escrow.functions.getLockedTokens(staker1, duration + 1).call() == 0
|
||||
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker1).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker1).call()
|
||||
|
||||
# Can't deposit tokens again for the same staker
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
execute_multisig_transaction(testerchain, multisig, [contracts_owners[0], contracts_owners[1]], tx)
|
||||
|
@ -500,10 +488,6 @@ def test_worklock_phases(testerchain,
|
|||
testerchain.wait_for_receipt(tx)
|
||||
assert worklock.functions.workInfo(staker2).call()[2]
|
||||
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker2).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker2).call()
|
||||
|
||||
assert token.functions.balanceOf(staker2).call() == 0
|
||||
assert escrow.functions.getLockedTokens(staker2, 0).call() == 0
|
||||
assert escrow.functions.getLockedTokens(staker2, 1).call() == staker2_tokens
|
||||
|
@ -533,10 +517,6 @@ def test_worklock_phases(testerchain,
|
|||
assert escrow.functions.getLockedTokens(staker1, 1).call() == pytest.staker1_tokens
|
||||
pytest.escrow_supply += staker1_claims
|
||||
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker1).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker1).call()
|
||||
|
||||
# Staker prolongs lock duration
|
||||
tx = escrow.functions.prolongStake(0, 3).transact({'from': staker2, 'gas_price': 0})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
|
|
@ -1267,28 +1267,14 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
creator = testerchain.client.accounts[0]
|
||||
deposit_log = escrow.events.Deposited.createFilter(fromBlock='latest')
|
||||
lock_log = escrow.events.Locked.createFilter(fromBlock='latest')
|
||||
re_stake_log = escrow.events.ReStakeSet.createFilter(fromBlock='latest')
|
||||
re_stake_lock_log = escrow.events.ReStakeLocked.createFilter(fromBlock='latest')
|
||||
|
||||
# Grant access to transfer tokens
|
||||
tx = token.functions.approve(escrow.address, 10000).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can deposit tokens only from owner
|
||||
staker = testerchain.client.accounts[1]
|
||||
tx = token.functions.transfer(staker, 1000).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.approve(escrow.address, 1000).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [1000], [10], 0)\
|
||||
.transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Deposit tokens for 1 staker
|
||||
tx = escrow.functions.setReStake(False).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [1000], [10], 0).transact({'from': creator})
|
||||
staker = testerchain.client.accounts[1]
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [1000], [10]).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
escrow_balance = 1000
|
||||
assert token.functions.balanceOf(escrow.address).call() == escrow_balance
|
||||
|
@ -1303,12 +1289,6 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert escrow.functions.getPastDowntimeLength(staker).call() == 0
|
||||
assert escrow.functions.getLastCommittedPeriod(staker).call() == 0
|
||||
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker).call()
|
||||
assert not re_stake
|
||||
assert not escrow.functions.isReStakeLocked(staker).call()
|
||||
staker_info = escrow.functions.stakerInfo(staker).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == 0
|
||||
|
||||
deposit_events = deposit_log.get_all_entries()
|
||||
assert len(deposit_events) == 1
|
||||
event_args = deposit_events[-1]['args']
|
||||
|
@ -1324,60 +1304,55 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert event_args['firstPeriod'] == current_period + 1
|
||||
assert event_args['periods'] == 10
|
||||
|
||||
events = re_stake_log.get_all_entries()
|
||||
assert len(events) == 1
|
||||
events = re_stake_lock_log.get_all_entries()
|
||||
assert len(events) == 0
|
||||
|
||||
# Can't deposit tokens again for the same staker twice
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [1000], [10], 0)\
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [1000], [10])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't deposit tokens with too low or too high value
|
||||
staker = testerchain.client.accounts[2]
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [1], [10], 0)\
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [1], [10])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [1501], [10], 0)\
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [1501], [10])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [500], [1], 0)\
|
||||
tx = escrow.functions.batchDeposit([staker], [1], [500], [1])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [2], [1000, 501], [10, 10], 0)\
|
||||
tx = escrow.functions.batchDeposit([staker], [2], [1000, 501], [10, 10])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Inconsistent input
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [0], [500], [10], 0)\
|
||||
tx = escrow.functions.batchDeposit([staker], [0], [500], [10])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [2], [500], [10], 0)\
|
||||
tx = escrow.functions.batchDeposit([staker], [2], [500], [10])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [1, 1], [500], [10], 0)\
|
||||
tx = escrow.functions.batchDeposit([staker], [1, 1], [500], [10])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [1, 1], [500, 500], [10], 0)\
|
||||
tx = escrow.functions.batchDeposit([staker], [1, 1], [500, 500], [10])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit([staker], [1, 1], [500, 500], [10, 10], 0)\
|
||||
tx = escrow.functions.batchDeposit([staker], [1, 1], [500, 500], [10, 10])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
stakers = testerchain.client.accounts[2:4]
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.batchDeposit(stakers, [1, 1], [500, 500, 500], [10, 10, 10], 0)\
|
||||
tx = escrow.functions.batchDeposit(stakers, [1, 1], [500, 500, 500], [10, 10, 10])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
|
@ -1386,24 +1361,24 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Deposit tokens for multiple stakers
|
||||
tx = token.functions.transfer(staker, 1500).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.approve(escrow.address, 1500).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
stakers = testerchain.client.accounts[2:7]
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = escrow.functions.batchDeposit(
|
||||
stakers, [1, 1, 1, 1, 1], [100, 200, 300, 400, 500], [50, 100, 150, 200, 250], current_period + 2
|
||||
).transact({'from': creator})
|
||||
stakers, [1, 1, 1, 1, 1], [100, 200, 300, 400, 500], [50, 100, 150, 200, 250]
|
||||
).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
escrow_balance += 1500
|
||||
assert token.functions.balanceOf(escrow.address).call() == escrow_balance
|
||||
deposit_events = deposit_log.get_all_entries()
|
||||
lock_events = lock_log.get_all_entries()
|
||||
re_stake_lock_events = re_stake_lock_log.get_all_entries()
|
||||
re_stake_events = re_stake_log.get_all_entries()
|
||||
|
||||
assert len(deposit_events) == 6
|
||||
assert len(lock_events) == 6
|
||||
assert len(re_stake_lock_events) == 5
|
||||
assert len(re_stake_events) == 1
|
||||
|
||||
for index, staker in enumerate(stakers):
|
||||
value = 100 * (index + 1)
|
||||
|
@ -1418,12 +1393,6 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert escrow.functions.getPastDowntimeLength(staker).call() == 0
|
||||
assert escrow.functions.getLastCommittedPeriod(staker).call() == 0
|
||||
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker).call()
|
||||
staker_info = escrow.functions.stakerInfo(staker).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == current_period + 2
|
||||
|
||||
event_args = deposit_events[index + 1]['args']
|
||||
assert event_args['staker'] == staker
|
||||
assert event_args['value'] == value
|
||||
|
@ -1435,22 +1404,12 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert event_args['firstPeriod'] == current_period + 1
|
||||
assert event_args['periods'] == duration
|
||||
|
||||
event_args = re_stake_lock_events[index]['args']
|
||||
assert event_args['staker'] == staker
|
||||
assert event_args['lockUntilPeriod'] == current_period + 2
|
||||
|
||||
# Deposit tokens for multiple stakers with multiple sub-stakes
|
||||
stakers = testerchain.client.accounts[7:10]
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = escrow.functions.setReStake(False).transact({'from': stakers[0]})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setReStake(False).transact({'from': stakers[1]})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.lockReStake(current_period + 4).transact({'from': stakers[1]})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = escrow.functions.batchDeposit(
|
||||
stakers, [1, 2, 3], [100, 200, 300, 400, 500, 600], [50, 100, 150, 200, 250, 300], current_period + 3)\
|
||||
stakers, [1, 2, 3], [100, 200, 300, 400, 500, 600], [50, 100, 150, 200, 250, 300])\
|
||||
.transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
|
@ -1458,13 +1417,9 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert token.functions.balanceOf(escrow.address).call() == escrow_balance
|
||||
deposit_events = deposit_log.get_all_entries()
|
||||
lock_events = lock_log.get_all_entries()
|
||||
re_stake_lock_events = re_stake_lock_log.get_all_entries()
|
||||
re_stake_events = re_stake_log.get_all_entries()
|
||||
|
||||
assert len(deposit_events) == 12
|
||||
assert len(lock_events) == 12
|
||||
assert len(re_stake_lock_events) == 8
|
||||
assert len(re_stake_events) == 5
|
||||
|
||||
staker = stakers[0]
|
||||
duration = 50
|
||||
|
@ -1479,12 +1434,6 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert escrow.functions.getLastCommittedPeriod(staker).call() == 0
|
||||
assert escrow.functions.getSubStakesLength(staker).call() == 1
|
||||
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker).call()
|
||||
staker_info = escrow.functions.stakerInfo(staker).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == current_period + 3
|
||||
|
||||
event_args = deposit_events[6]['args']
|
||||
assert event_args['staker'] == staker
|
||||
assert event_args['value'] == value
|
||||
|
@ -1496,14 +1445,6 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert event_args['firstPeriod'] == current_period + 1
|
||||
assert event_args['periods'] == duration
|
||||
|
||||
event_args = re_stake_events[3]['args']
|
||||
assert event_args['staker'] == staker
|
||||
assert event_args['reStake']
|
||||
|
||||
event_args = re_stake_lock_events[6]['args']
|
||||
assert event_args['staker'] == staker
|
||||
assert event_args['lockUntilPeriod'] == current_period + 3
|
||||
|
||||
staker = stakers[1]
|
||||
duration1 = 100
|
||||
duration2 = 150
|
||||
|
@ -1522,12 +1463,6 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert escrow.functions.getLastCommittedPeriod(staker).call() == 0
|
||||
assert escrow.functions.getSubStakesLength(staker).call() == 2
|
||||
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker).call()
|
||||
staker_info = escrow.functions.stakerInfo(staker).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == current_period + 4
|
||||
|
||||
event_args = deposit_events[7]['args']
|
||||
assert event_args['staker'] == staker
|
||||
assert event_args['value'] == value1
|
||||
|
@ -1550,10 +1485,6 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert event_args['firstPeriod'] == current_period + 1
|
||||
assert event_args['periods'] == duration2
|
||||
|
||||
event_args = re_stake_events[4]['args']
|
||||
assert event_args['staker'] == staker
|
||||
assert event_args['reStake']
|
||||
|
||||
staker = stakers[2]
|
||||
duration1 = 200
|
||||
duration2 = 250
|
||||
|
@ -1576,12 +1507,6 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert escrow.functions.getLastCommittedPeriod(staker).call() == 0
|
||||
assert escrow.functions.getSubStakesLength(staker).call() == 3
|
||||
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker).call()
|
||||
staker_info = escrow.functions.stakerInfo(staker).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == current_period + 3
|
||||
|
||||
event_args = deposit_events[9]['args']
|
||||
assert event_args['staker'] == staker
|
||||
assert event_args['value'] == value1
|
||||
|
@ -1615,10 +1540,6 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert event_args['firstPeriod'] == current_period + 1
|
||||
assert event_args['periods'] == duration3
|
||||
|
||||
event_args = re_stake_lock_events[7]['args']
|
||||
assert event_args['staker'] == staker
|
||||
assert event_args['lockUntilPeriod'] == current_period + 3
|
||||
|
||||
|
||||
def test_staking_from_worklock(testerchain, token, escrow_contract, token_economics, deploy_contract):
|
||||
"""
|
||||
|
@ -1630,8 +1551,6 @@ def test_staking_from_worklock(testerchain, token, escrow_contract, token_econom
|
|||
creator, staker1, staker2, staker3, staker4 = testerchain.client.accounts[0:5]
|
||||
deposit_log = escrow.events.Deposited.createFilter(fromBlock='latest')
|
||||
lock_log = escrow.events.Locked.createFilter(fromBlock='latest')
|
||||
re_stake_log = escrow.events.ReStakeSet.createFilter(fromBlock='latest')
|
||||
re_stake_lock_log = escrow.events.ReStakeLocked.createFilter(fromBlock='latest')
|
||||
|
||||
# Deploy WorkLock mock
|
||||
worklock, _ = deploy_contract('WorkLockForStakingEscrowMock', token.address, escrow.address)
|
||||
|
@ -1651,11 +1570,6 @@ def test_staking_from_worklock(testerchain, token, escrow_contract, token_econom
|
|||
tx = escrow.functions.depositFromWorkLock(staker1, value, duration).transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert token.functions.balanceOf(escrow.address).call() == 0
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker1).call()
|
||||
assert re_stake
|
||||
assert not escrow.functions.isReStakeLocked(staker1).call()
|
||||
staker_info = escrow.functions.stakerInfo(staker1).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == 0
|
||||
|
||||
# Deposit tokens from WorkLock
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
|
@ -1666,11 +1580,6 @@ def test_staking_from_worklock(testerchain, token, escrow_contract, token_econom
|
|||
assert escrow.functions.getLockedTokens(staker1, 1).call() == value
|
||||
assert escrow.functions.getLockedTokens(staker1, duration).call() == value
|
||||
assert escrow.functions.getLockedTokens(staker1, duration + 1).call() == 0
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker1).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker1).call()
|
||||
staker_info = escrow.functions.stakerInfo(staker1).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == current_period + duration + 1
|
||||
|
||||
# Check that all events are emitted
|
||||
events = deposit_log.get_all_entries()
|
||||
|
@ -1687,158 +1596,3 @@ def test_staking_from_worklock(testerchain, token, escrow_contract, token_econom
|
|||
assert event_args['value'] == value
|
||||
assert event_args['firstPeriod'] == current_period + 1
|
||||
assert event_args['periods'] == duration
|
||||
|
||||
events = re_stake_log.get_all_entries()
|
||||
assert len(events) == 0
|
||||
events = re_stake_lock_log.get_all_entries()
|
||||
assert len(events) == 1
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker1
|
||||
assert event_args['lockUntilPeriod'] == current_period + duration + 1
|
||||
|
||||
# Staker disables `reStake` parameter before depositing tokens
|
||||
duration += 1
|
||||
value += 1
|
||||
tx = escrow.functions.setReStake(False).transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker2).call()
|
||||
assert not re_stake
|
||||
events = re_stake_log.get_all_entries()
|
||||
assert len(events) == 1
|
||||
|
||||
tx = worklock.functions.depositFromWorkLock(staker2, value, duration).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert escrow.functions.getLockedTokens(staker2, 0).call() == 0
|
||||
assert escrow.functions.getLockedTokens(staker2, 1).call() == value
|
||||
assert escrow.functions.getLockedTokens(staker2, duration).call() == value
|
||||
assert escrow.functions.getLockedTokens(staker2, duration + 1).call() == 0
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker2).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker2).call()
|
||||
staker_info = escrow.functions.stakerInfo(staker2).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == current_period + duration + 1
|
||||
|
||||
events = deposit_log.get_all_entries()
|
||||
assert len(events) == 2
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker2
|
||||
assert event_args['value'] == value
|
||||
assert event_args['periods'] == duration
|
||||
|
||||
events = lock_log.get_all_entries()
|
||||
assert len(events) == 2
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker2
|
||||
assert event_args['value'] == value
|
||||
assert event_args['firstPeriod'] == current_period + 1
|
||||
assert event_args['periods'] == duration
|
||||
|
||||
events = re_stake_log.get_all_entries()
|
||||
assert len(events) == 2
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker2
|
||||
assert event_args['reStake']
|
||||
|
||||
events = re_stake_lock_log.get_all_entries()
|
||||
assert len(events) == 2
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker2
|
||||
assert event_args['lockUntilPeriod'] == current_period + duration + 1
|
||||
|
||||
# Staker locks `reStake` parameter before depositing tokens for short period
|
||||
duration += 1
|
||||
value += 1
|
||||
tx = escrow.functions.setReStake(False).transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.lockReStake(current_period + duration).transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
staker_info = escrow.functions.stakerInfo(staker3).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == current_period + duration
|
||||
|
||||
events = re_stake_log.get_all_entries()
|
||||
assert len(events) == 3
|
||||
events = re_stake_lock_log.get_all_entries()
|
||||
assert len(events) == 3
|
||||
|
||||
tx = worklock.functions.depositFromWorkLock(staker3, value, duration).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert escrow.functions.getLockedTokens(staker3, 0).call() == 0
|
||||
assert escrow.functions.getLockedTokens(staker3, 1).call() == value
|
||||
assert escrow.functions.getLockedTokens(staker3, duration).call() == value
|
||||
assert escrow.functions.getLockedTokens(staker3, duration + 1).call() == 0
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker3).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker3).call()
|
||||
staker_info = escrow.functions.stakerInfo(staker3).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == current_period + duration + 1
|
||||
|
||||
events = deposit_log.get_all_entries()
|
||||
assert len(events) == 3
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker3
|
||||
assert event_args['value'] == value
|
||||
assert event_args['periods'] == duration
|
||||
|
||||
events = lock_log.get_all_entries()
|
||||
assert len(events) == 3
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker3
|
||||
assert event_args['value'] == value
|
||||
assert event_args['firstPeriod'] == current_period + 1
|
||||
assert event_args['periods'] == duration
|
||||
|
||||
events = re_stake_log.get_all_entries()
|
||||
assert len(events) == 4
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker3
|
||||
assert event_args['reStake']
|
||||
|
||||
events = re_stake_lock_log.get_all_entries()
|
||||
assert len(events) == 4
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker3
|
||||
assert event_args['lockUntilPeriod'] == current_period + duration + 1
|
||||
|
||||
# Staker locks `reStake` parameter before depositing tokens for long duration
|
||||
duration += 1
|
||||
value += 1
|
||||
tx = escrow.functions.lockReStake(current_period + duration + 1).transact({'from': staker4})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
staker_info = escrow.functions.stakerInfo(staker4).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == current_period + duration + 1
|
||||
|
||||
events = re_stake_lock_log.get_all_entries()
|
||||
assert len(events) == 5
|
||||
|
||||
tx = worklock.functions.depositFromWorkLock(staker4, value, duration).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert escrow.functions.getLockedTokens(staker4, 0).call() == 0
|
||||
assert escrow.functions.getLockedTokens(staker4, 1).call() == value
|
||||
assert escrow.functions.getLockedTokens(staker4, duration).call() == value
|
||||
assert escrow.functions.getLockedTokens(staker4, duration + 1).call() == 0
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker4).call()
|
||||
assert re_stake
|
||||
assert escrow.functions.isReStakeLocked(staker4).call()
|
||||
staker_info = escrow.functions.stakerInfo(staker4).call()
|
||||
assert staker_info[LOCK_RE_STAKE_UNTIL_PERIOD_FIELD] == current_period + duration + 1
|
||||
|
||||
events = deposit_log.get_all_entries()
|
||||
assert len(events) == 4
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker4
|
||||
assert event_args['value'] == value
|
||||
assert event_args['periods'] == duration
|
||||
|
||||
events = lock_log.get_all_entries()
|
||||
assert len(events) == 4
|
||||
event_args = events[-1]['args']
|
||||
assert event_args['staker'] == staker4
|
||||
assert event_args['value'] == value
|
||||
assert event_args['firstPeriod'] == current_period + 1
|
||||
assert event_args['periods'] == duration
|
||||
|
||||
events = re_stake_log.get_all_entries()
|
||||
assert len(events) == 4
|
||||
|
||||
events = re_stake_lock_log.get_all_entries()
|
||||
assert len(events) == 5
|
||||
|
|
|
@ -242,8 +242,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
staker_functions.batchDeposit(everyone_else[0:5],
|
||||
[2] * 5,
|
||||
[MIN_ALLOWED_LOCKED] * 10,
|
||||
[MIN_LOCKED_PERIODS] * 10,
|
||||
current_period + 5),
|
||||
[MIN_LOCKED_PERIODS] * 10),
|
||||
{'from': origin})
|
||||
|
||||
transact(token_functions.approve(staking_agent.contract_address, MIN_ALLOWED_LOCKED * 24), {'from': origin})
|
||||
|
@ -251,8 +250,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
staker_functions.batchDeposit([everyone_else[6]],
|
||||
[24],
|
||||
[MIN_ALLOWED_LOCKED] * 24,
|
||||
[MIN_LOCKED_PERIODS] * 24,
|
||||
current_period + 5),
|
||||
[MIN_LOCKED_PERIODS] * 24),
|
||||
{'from': origin})
|
||||
|
||||
transact(token_functions.approve(staking_agent.contract_address, MIN_ALLOWED_LOCKED * 24 * 5), {'from': origin})
|
||||
|
@ -260,8 +258,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
staker_functions.batchDeposit(everyone_else[7:12],
|
||||
[24]*5,
|
||||
[MIN_ALLOWED_LOCKED] * (24 * 5),
|
||||
[MIN_LOCKED_PERIODS] * (24 * 5),
|
||||
current_period + 5),
|
||||
[MIN_LOCKED_PERIODS] * (24 * 5)),
|
||||
{'from': origin})
|
||||
|
||||
#
|
||||
|
@ -588,8 +585,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
transact(staker_functions.batchDeposit([staker4],
|
||||
[number_of_sub_stakes],
|
||||
[MIN_ALLOWED_LOCKED] * number_of_sub_stakes,
|
||||
[MIN_LOCKED_PERIODS] * number_of_sub_stakes,
|
||||
current_period + 100),
|
||||
[MIN_LOCKED_PERIODS] * number_of_sub_stakes),
|
||||
{'from': origin})
|
||||
transact(staker_functions.bondWorker(staker4), {'from': staker4})
|
||||
transact(staker_functions.setWindDown(True), {'from': staker4})
|
||||
|
|
Loading…
Reference in New Issue