Expose more worklock methods on agency; Adjust claim requirements.; CLI warning for small bids.

pull/1550/head
Kieran R. Prasch 2020-01-30 13:16:09 -08:00
parent 0a396410e6
commit ec78da448e
4 changed files with 37 additions and 12 deletions

View File

@ -1421,12 +1421,6 @@ class Bidder(NucypherTokenActor):
def place_bid(self, value: int) -> dict:
# wei_bid = Web3.toWei(value, 'wei') # TODO: Consider default denomination on this layer
self._ensure_bidding_is_open()
# Ensure the bid is at least large enough for min. stake
minimum = self.economics.minimum_allowed_locked
if value < minimum:
raise ValueError(f"Bid amount must be at least {NU.from_nunits(minimum)}")
receipt = self.worklock_agent.bid(checksum_address=self.checksum_address, value=value)
return receipt
@ -1441,10 +1435,15 @@ class Bidder(NucypherTokenActor):
if self._has_claimed:
raise self.BidderError(f"Bidder {self.checksum_address} already placed a claim.")
# Require an available refund
# Require an active bid
if not self.current_bid:
raise self.BidderError(f"No claims available for {self.checksum_address}")
# Ensure the claim is at least large enough for min. stake
minimum = self.economics.minimum_allowed_locked
if self.available_claim < minimum:
raise ValueError(f"Claim is too small. Claim amount must be worth at least {NU.from_nunits(minimum)})")
receipt = self.worklock_agent.claim(checksum_address=self.checksum_address)
return receipt
@ -1473,9 +1472,9 @@ class Bidder(NucypherTokenActor):
#
@property
def current_bid(self, denomination: str = None) -> int:
def current_bid(self, denomination: str = 'wei') -> int:
bid = self.worklock_agent.get_bid(checksum_address=self.checksum_address)
ether_bid = Web3.toWei(bid, denomination or 'wei') # TODO: Consider default denomination on this layer
ether_bid = Web3.toWei(bid, denomination) # TODO: Consider ether as the default denomination on this layer
return ether_bid
@property
@ -1506,3 +1505,8 @@ class Bidder(NucypherTokenActor):
def available_refund(self) -> int:
refund_eth = self.worklock_agent.get_available_refund(completed_work=self.completed_work)
return refund_eth
@property
def available_claim(self) -> int:
tokens = self.worklock_agent.eth_to_tokens(self.current_bid)
return tokens

View File

@ -1069,6 +1069,18 @@ class WorkLockAgent(EthereumContractAgent):
tokens = self.contract.functions.unclaimedTokens().call()
return tokens
def eth_to_tokens(self, value: int) -> int:
tokens = self.contract.functions.ethToTokens(value).call()
return tokens
def eth_to_work(self, value: int) -> int:
tokens = self.contract.functions.ethToWork(value).call()
return tokens
def work_to_eth(self, value: int) -> int:
tokens = self.contract.functions.workToETH(value).call()
return tokens
@property
def start_date(self) -> int:
date = self.contract.functions.startBidDate().call()

View File

@ -21,10 +21,12 @@ from web3 import Web3
from nucypher.blockchain.eth.actors import Bidder
from nucypher.blockchain.eth.agents import ContractAgency, WorkLockAgent
from nucypher.blockchain.eth.token import NU
from nucypher.characters.banners import WORKLOCK_BANNER
from nucypher.cli.actions import select_client_account
from nucypher.cli.options import option_force, group_options, option_checksum_address
from nucypher.cli.commands.status import group_registry_options
from nucypher.cli.config import group_general_config
from nucypher.cli.options import option_force, group_options, option_checksum_address
from nucypher.cli.painting import (
paint_receipt_summary,
paint_worklock_status,
@ -32,7 +34,6 @@ from nucypher.cli.painting import (
paint_bidder_status,
paint_worklock_claim
)
from nucypher.cli.commands.status import group_registry_options
from nucypher.cli.types import EIP55_CHECKSUM_ADDRESS
option_bidder_address = click.option('--bidder-address',
@ -111,6 +112,14 @@ def bid(general_config, worklock_options, registry_options, force, value):
receipt = bidder.place_bid(value=value)
emitter.message("Publishing WorkLock Bid...")
# Ensure the claim is at least large enough for min. stake
minimum = bidder.economics.minimum_allowed_locked
value = bidder.worklock_agent.eth_to_tokens(bidder.current_bid)
if value < minimum:
warning = f"Bid is too small for a claim, please bid more. (Bid value total must be at least {NU.from_nunits(minimum)})"
click.secho(warning, color='yellow')
paint_receipt_summary(receipt=receipt, emitter=emitter, chain_name=bidder.staking_agent.blockchain.client.chain_name)
return # Exit

View File

@ -48,7 +48,7 @@ def test_worklock_deployment(worklock_deployer, staking_escrow_deployer, deploym
# deployment steps must match expected number of steps
steps = worklock_deployer.deployment_steps
assert deployment_progress.num_steps == len(steps) == len(deployment_receipts) == 3
assert deployment_progress.num_steps == len(steps) == len(deployment_receipts) == 4
# Ensure every step is successful
for step_title in steps: