mirror of https://github.com/nucypher/nucypher.git
Changed unlocking in the UserEscrow
parent
41d24f9ad9
commit
48ce0a6428
|
@ -6,7 +6,7 @@ NuCypher contracts
|
|||
* `Upgradeable` is base contract for upgrading (<nucypher.blockchain.eth/project/contracts/proxy/README.MD>)
|
||||
* `Dispatcher` contract is used as proxy to other contracts. This provides upgrading of the `MinersEscrow`, `PolicyManager` and `Government` contracts
|
||||
* `Government` contract holds ownership for dispatchers and provides voting for upgrading of those contracts
|
||||
* `UserEscrow` contract locks tokens for some time. In that period tokens are lineraly unlocked and all tokens can be used as a stake in the `MinersEscrow` contract
|
||||
* `UserEscrow` contract locks tokens for some time. Tokens will be unlocked after specified time and all tokens can be used as a stake in the `MinersEscrow` contract
|
||||
|
||||
Deployment
|
||||
========================
|
||||
|
@ -65,8 +65,8 @@ The miner can set a minimum reward rate for a policy. For that, the miner should
|
|||
|
||||
Some users will have locked but not staked tokens.
|
||||
In that case, a instance of the `UserEscrow` contract will hold their tokens (method `initialDeposit(uint256, uint256)`).
|
||||
All tokens will be linearly unlocked and the user can get them by method `withdraw(uint256)`.
|
||||
When the user wants to become a miner - he uses the `UserEscrow` contract as a proxy for the `MinersEscrow` and `PolicyManager` contracts.
|
||||
All tokens will be unlocked after specified time and the user can get them by method `withdraw(uint256)`.
|
||||
When the user wants to become a miner - he uses the `UserEscrow` contract as a proxy for the `MinersEscrow`, `PolicyManager` and `Government` contracts.
|
||||
|
||||
Alice
|
||||
========================
|
||||
|
|
|
@ -43,7 +43,6 @@ contract UserEscrow is Ownable {
|
|||
Government public government;
|
||||
uint256 public lockedValue;
|
||||
uint256 public endLockTimestamp;
|
||||
uint256 public lockDuration;
|
||||
|
||||
/**
|
||||
* @notice Constructor sets addresses of the contracts
|
||||
|
@ -80,7 +79,6 @@ contract UserEscrow is Ownable {
|
|||
function initialDeposit(uint256 _value, uint256 _duration) public {
|
||||
require(lockedValue == 0 && _value > 0);
|
||||
endLockTimestamp = block.timestamp.add(_duration);
|
||||
lockDuration = _duration;
|
||||
lockedValue = _value;
|
||||
token.safeTransferFrom(msg.sender, address(this), _value);
|
||||
emit Deposited(msg.sender, _value, _duration);
|
||||
|
@ -93,8 +91,7 @@ contract UserEscrow is Ownable {
|
|||
if (endLockTimestamp <= block.timestamp) {
|
||||
return 0;
|
||||
}
|
||||
return lockedValue.mul(endLockTimestamp.sub(block.timestamp))
|
||||
.div(lockDuration);
|
||||
return lockedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
pragma solidity ^0.4.23;
|
||||
|
||||
|
||||
/**
|
||||
* @notice Contract for testing user escrow contract
|
||||
**/
|
||||
contract GovernmentForUserEscrowMock {
|
||||
|
||||
bool public voteFor;
|
||||
|
||||
function vote(bool _voteFor) public {
|
||||
voteFor = _voteFor;
|
||||
}
|
||||
|
||||
}
|
|
@ -99,7 +99,6 @@ def test_escrow(web3, chain, token, user_escrow):
|
|||
assert 1000 == token.functions.balanceOf(user_escrow.address).call()
|
||||
|
||||
events = withdraws.get_all_entries()
|
||||
|
||||
assert 1 == len(events)
|
||||
event_args = events[0]['args']
|
||||
assert user == event_args['owner']
|
||||
|
@ -107,37 +106,27 @@ def test_escrow(web3, chain, token, user_escrow):
|
|||
|
||||
# Wait some time
|
||||
chain.time_travel(seconds=500)
|
||||
assert 500 >= user_escrow.functions.getLockedTokens().call()
|
||||
assert 450 <= user_escrow.functions.getLockedTokens().call()
|
||||
assert 1000 == user_escrow.functions.getLockedTokens().call()
|
||||
|
||||
# User can withdraw some unlocked tokens
|
||||
tx = user_escrow.functions.withdraw(500).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 1500 == token.functions.balanceOf(user).call()
|
||||
|
||||
# events = user_escrow.pastEvents('Withdrawn').get()
|
||||
events = withdraws.get_all_entries()
|
||||
|
||||
assert 2 == len(events)
|
||||
event_args = events[1]['args']
|
||||
assert user == event_args['owner']
|
||||
assert 500 == event_args['value']
|
||||
# Can't withdraw before unlocking
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = user_escrow.functions.withdraw(100).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 1000 == token.functions.balanceOf(user).call()
|
||||
|
||||
# Wait more time and withdraw all
|
||||
chain.time_travel(seconds=500)
|
||||
assert 0 == user_escrow.functions.getLockedTokens().call()
|
||||
tx = user_escrow.functions.withdraw(500).transact({'from': user})
|
||||
tx = user_escrow.functions.withdraw(1000).transact({'from': user})
|
||||
chain.wait_for_receipt(tx)
|
||||
assert 0 == token.functions.balanceOf(user_escrow.address).call()
|
||||
assert 2000 == token.functions.balanceOf(user).call()
|
||||
|
||||
# events = user_escrow.pastEvents('Withdrawn').get()
|
||||
events = withdraws.get_all_entries()
|
||||
|
||||
assert 3 == len(events)
|
||||
event_args = events[2]['args']
|
||||
assert 2 == len(events)
|
||||
event_args = events[1]['args']
|
||||
assert user == event_args['owner']
|
||||
assert 500 == event_args['value']
|
||||
assert 1000 == event_args['value']
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
|
|
Loading…
Reference in New Issue