def close( auction_address, keystore: str, jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, ): web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) contracts = get_deployed_auction_contracts(web3, auction_address) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) auction_close = contracts.auction.functions.closeAuction() send_function_call_transaction( auction_close, web3=web3, transaction_options=transaction_options, private_key=private_key, )
def exchange(jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, keystore: str): """Deploy an exchange contract and a contract to wrap Ether into an ERC 20 token. """ web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) exchange_contract = deploy_exchange( web3=web3, transaction_options=transaction_options, private_key=private_key) exchange_address = exchange_contract.address unw_eth_contract = deploy_unw_eth( web3=web3, transaction_options=transaction_options, private_key=private_key, exchange_address=exchange_address, ) unw_eth_address = unw_eth_contract.address click.echo("Exchange: {}".format(to_checksum_address(exchange_address))) click.echo("Unwrapping ether: {}".format( to_checksum_address(unw_eth_address)))
def deploy_foreign( keystore: str, jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, token_address, ) -> None: web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) nonce = get_nonce( web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key ) transaction_options = build_transaction_options( gas=gas, gas_price=gas_price, nonce=nonce ) foreign_bridge_contract = deploy_foreign_bridge_contract( token_contract_address=token_address, web3=web3, transaction_options=transaction_options, private_key=private_key, ) click.echo(f"ForeignBridge address: {foreign_bridge_contract.address}") click.echo(f" deployed at block #{web3.eth.blockNumber}")
def deploy_home( keystore: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, jsonrpc: str, validator_proxy_address: str, validators_required_percent: int, ) -> None: web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) nonce = get_nonce( web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key ) transaction_options = build_transaction_options( gas=gas, gas_price=gas_price, nonce=nonce ) home_bridge_contract = deploy_home_bridge_contract( validator_proxy_contract_address=validator_proxy_address, validators_required_percent=validators_required_percent, web3=web3, transaction_options=transaction_options, private_key=private_key, ) click.echo(f"HomeBridge address: {home_bridge_contract.address}") click.echo(f" deployed at block #{web3.eth.blockNumber}")
def report_via_file( keystore: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, jsonrpc: str, contract_address, equivocation_report, ) -> None: web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) tx_hash = report_malicious_validator( web3, transaction_options, private_key, contract_address, equivocation_report["unsigned_block_header_one"], equivocation_report["signature_one"], equivocation_report["unsigned_block_header_two"], equivocation_report["signature_two"], ) click.echo(f"Transaction hash: {tx_hash}")
def deploy( keystore: str, jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, token_address: str, airdrop_file_name: str, decay_start_time: int, decay_start_date: pendulum.DateTime, decay_duration: int, ) -> None: if decay_start_date is not None and decay_start_time is not None: raise click.BadParameter( "Both --decay-start-date and --decay-start-time have been specified" ) if decay_start_date is None and decay_start_time is None: raise click.BadParameter( "Please specify a decay start date with --decay-start-date or --decay-start-time" ) if decay_start_date is not None: decay_start_time = int(decay_start_date.timestamp()) web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) airdrop_data = load_airdrop_file(airdrop_file_name) airdrop_items = to_items(airdrop_data) merkle_root = compute_merkle_root(airdrop_items) constructor_args = ( token_address, sum_of_airdropped_tokens(airdrop_items), merkle_root, decay_start_time, decay_duration, ) merkle_drop = deploy_merkle_drop( web3=web3, transaction_options=transaction_options, private_key=private_key, constructor_args=constructor_args, ) click.echo(f"MerkleDrop address: {merkle_drop.address}") click.echo(f"Merkle root: {encode_hex(merkle_root)}")
def identity_proxy_factory(jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, keystore: str): """Deploy an identity proxy factory, which can be used to create proxies for identity contracts. """ web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) identity_proxy_factory = deploy_identity_proxy_factory( web3=web3, transaction_options=transaction_options, private_key=private_key) click.echo("Identity proxy factory: {}".format( to_checksum_address(identity_proxy_factory.address)))
def identity_implementation(jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, keystore: str): """Deploy an identity contract without initializing it. Can be used as the implementation for deployed identity proxies. """ web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) identity_implementation = deploy_identity_implementation( web3=web3, transaction_options=transaction_options, private_key=private_key) click.echo("Identity implementation: {}".format( to_checksum_address(identity_implementation.address)))
def whitelist( whitelist_file: str, auction_address: str, batch_size: int, keystore: str, jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, ) -> None: web3 = connect_to_json_rpc(jsonrpc) whitelist = read_addresses_in_csv(whitelist_file) private_key = retrieve_private_key(keystore) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) contracts = get_deployed_auction_contracts(web3, auction_address) number_of_whitelisted_addresses = whitelist_addresses( contracts.auction, whitelist, batch_size=batch_size, web3=web3, transaction_options=transaction_options, private_key=private_key, ) click.echo("Number of whitelisted addresses: " + str(number_of_whitelisted_addresses))
def deploy( start_price: int, auction_duration: int, minimal_number_of_participants: int, maximal_number_of_participants: int, release_timestamp: int, release_date: pendulum.DateTime, keystore: str, jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, ) -> None: if release_date is not None and release_timestamp is not None: raise click.BadParameter( f"Both --release-date and --release-timestamp have been specified") if release_date is None and release_timestamp is None: raise click.BadParameter( f"Please specify a release date with --release-date or --release-timestamp" ) if release_date is not None: release_timestamp = int(release_date.timestamp()) web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) auction_options = AuctionOptions( start_price * ETH_IN_WEI, auction_duration, minimal_number_of_participants, maximal_number_of_participants, release_timestamp, ) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) contracts = deploy_auction_contracts( web3=web3, transaction_options=transaction_options, private_key=private_key, auction_options=auction_options, ) initialize_auction_contracts( web3=web3, transaction_options=transaction_options, contracts=contracts, release_timestamp=release_timestamp, private_key=private_key, ) click.echo("Auction address: " + contracts.auction.address) click.echo("Deposit locker address: " + contracts.locker.address) click.echo("Validator slasher address: " + contracts.slasher.address)
def deploy( start_price: int, auction_duration: int, minimal_number_of_participants: int, maximal_number_of_participants: int, use_token: bool, token_address: Optional[str], release_timestamp: int, release_date: pendulum.DateTime, keystore: str, jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, already_deployed_auction, already_deployed_locker, already_deployed_slasher, ) -> None: if use_token and token_address is None: raise click.BadParameter( "The flag `use-token` was provided, the token address must also be provided via `token-address`" ) if token_address is not None and not use_token: raise click.BadParameter( "A token address has been provided, " "please use the flag --use-token to confirm you want to deploy a token auction" ) if release_date is not None and release_timestamp is not None: raise click.BadParameter( "Both --release-date and --release-timestamp have been specified") if release_date is None and release_timestamp is None: raise click.BadParameter( "Please specify a release date with --release-date or --release-timestamp" ) if already_deployed_auction is not None and already_deployed_locker is None: raise click.BadOptionUsage( "--auction", "Cannot resume deployment from already deployed auction without already deployed locker. " "Locker address is part of auction's constructor argument.", ) if release_date is not None: release_timestamp = int(release_date.timestamp()) web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) auction_options = AuctionOptions( start_price * ETH_IN_WEI, auction_duration, minimal_number_of_participants, maximal_number_of_participants, release_timestamp, token_address, ) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) contracts = deploy_auction_contracts( web3=web3, transaction_options=transaction_options, private_key=private_key, auction_options=auction_options, already_deployed_contracts=DeployedContractsAddresses( already_deployed_locker, already_deployed_slasher, already_deployed_auction), ) initialize_auction_contracts( web3=web3, transaction_options=transaction_options, contracts=contracts, release_timestamp=release_timestamp, token_address=token_address, private_key=private_key, ) slasher: Contract = contracts.slasher click.echo("Auction address: " + contracts.auction.address) click.echo("Deposit locker address: " + contracts.locker.address) click.echo("Validator slasher address: " + slasher.address) warning_messages = get_errors_messages_on_contracts_links(contracts) if warning_messages: warning_messages.append( "Verify what is wrong with `auction-deploy status`.") click.secho(linesep.join(warning_messages), fg="red")
def test( jsonrpc: str, file: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, keystore: str, currency_network_contract_name: str, ): """Deploy three test currency network contracts connected to an exchange contract and an unwrapping ether contract. Also deploys an identity proxy factory and a identity implementation contract. This can be used for testing""" expiration_time = 4_102_444_800 # 01/01/2100 network_settings = [ { "name": "Cash", "symbol": "CASH", "decimals": 4, "fee_divisor": 1000, "default_interest_rate": 0, "custom_interests": True, "expiration_time": expiration_time, }, { "name": "Work Hours", "symbol": "HOU", "decimals": 4, "fee_divisor": 0, "default_interest_rate": 1000, "custom_interests": False, "expiration_time": expiration_time, }, { "name": "Beers", "symbol": "BEER", "decimals": 0, "fee_divisor": 0, "custom_interests": False, "expiration_time": expiration_time, }, ] web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) networks, exchange, unw_eth = deploy_networks( web3, network_settings, currency_network_contract_name=currency_network_contract_name, ) identity_implementation = deploy_identity_implementation( web3=web3, transaction_options=transaction_options, private_key=private_key) identity_proxy_factory = deploy_identity_proxy_factory( web3=web3, transaction_options=transaction_options, private_key=private_key) addresses = dict() network_addresses = [network.address for network in networks] exchange_address = exchange.address unw_eth_address = unw_eth.address addresses["networks"] = network_addresses addresses["exchange"] = exchange_address addresses["unwEth"] = unw_eth_address addresses["identityImplementation"] = identity_implementation.address addresses["identityProxyFactory"] = identity_proxy_factory.address if file: with open(file, "w") as outfile: json.dump(addresses, outfile) click.echo("Exchange: {}".format(to_checksum_address(exchange_address))) click.echo("Unwrapping ether: {}".format( to_checksum_address(unw_eth_address))) click.echo("Identity proxy factory: {}".format( to_checksum_address(identity_proxy_factory.address))) click.echo("Identity implementation: {}".format( to_checksum_address(identity_implementation.address))) for settings, address in zip(network_settings, network_addresses): click.echo("CurrencyNetwork({settings}) at {address}".format( settings=settings, address=to_checksum_address(address)))
def currencynetwork( name: str, symbol: str, decimals: int, jsonrpc: str, fee_rate: float, default_interest_rate: float, custom_interests: bool, prevent_mediator_interests: bool, exchange_contract: str, currency_network_contract_name: str, expiration_time: int, expiration_date: pendulum.DateTime, gas: int, gas_price: int, nonce: int, auto_nonce: bool, keystore: str, ): """Deploy a currency network contract with custom settings and optionally connect it to an exchange contract""" if exchange_contract is not None and not is_checksum_address( exchange_contract): raise click.BadParameter( "{} is not a valid address.".format(exchange_contract)) if custom_interests and default_interest_rate != 0.0: raise click.BadParameter("Custom interests can only be set without a" " default interest rate, but was {}%.".format( default_interest_rate)) if prevent_mediator_interests and not custom_interests: raise click.BadParameter( "Prevent mediator interests is not necessary if custom interests are disabled." ) if expiration_date is not None and expiration_time is not None: raise click.BadParameter( f"Both --expiration-date and --expiration-times have been specified." ) if expiration_date is None and expiration_time is None: expiration_time = 0 if expiration_date is not None: expiration_time = int(expiration_date.timestamp()) fee_divisor = 1 / fee_rate * 100 if fee_rate != 0 else 0 if int(fee_divisor) != fee_divisor: raise click.BadParameter("This fee rate is not usable") fee_divisor = int(fee_divisor) default_interest_rate = default_interest_rate * 100 if int(default_interest_rate) != default_interest_rate: raise click.BadParameter("This default interest rate is not usable") default_interest_rate = int(default_interest_rate) web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) contract = deploy_network( web3, name, symbol, decimals, fee_divisor=fee_divisor, default_interest_rate=default_interest_rate, custom_interests=custom_interests, prevent_mediator_interests=prevent_mediator_interests, exchange_address=exchange_contract, currency_network_contract_name=currency_network_contract_name, expiration_time=expiration_time, transaction_options=transaction_options, private_key=private_key, ) click.echo("CurrencyNetwork(name={name}, symbol={symbol}, " "decimals={decimals}, fee_divisor={fee_divisor}, " "default_interest_rate={default_interest_rate}, " "custom_interests={custom_interests}, " "prevent_mediator_interests={prevent_mediator_interests}, " "exchange_address={exchange_address}): {address}".format( name=name, symbol=symbol, decimals=decimals, fee_divisor=fee_divisor, default_interest_rate=default_interest_rate, custom_interests=custom_interests, prevent_mediator_interests=prevent_mediator_interests, exchange_address=exchange_contract, address=to_checksum_address(contract.address), ))