def token_contract(ether_owning_whitelist): contract_assets = load_contracts_json("auction_deploy") abi = contract_assets["TrustlinesNetworkToken"]["abi"] bytecode = contract_assets["TrustlinesNetworkToken"]["bytecode"] token_name = "Trustlines Network Token" token_symbol = "TLN" token_decimal = 18 number_to_mint = 10 * 10**18 premint_address = ether_owning_whitelist[0] constructor_args = ( token_name, token_symbol, token_decimal, premint_address, number_to_mint, ) token_contract = deploy_compiled_contract( abi=abi, bytecode=bytecode, web3=test_json_rpc, constructor_args=constructor_args, ) token_contract.functions.transfer(ether_owning_whitelist[1], int(number_to_mint / 2)).transact( {"from": ether_owning_whitelist[0]}) return token_contract
def get_bid_token_address(web3, auction_address: str): compiled_contracts = load_contracts_json(__name__) auction_abi = compiled_contracts["TokenValidatorAuction"]["abi"] auction = web3.eth.contract(address=auction_address, abi=auction_abi) try: return auction.functions.bidToken().call() except BadFunctionCallOutput: # Thrown by web3 when function does not exist on contract return None
def get_merkle_drop_status(web3, contract_address): compiled_contracts = load_contracts_json(__name__) merkle_drop_contract = web3.eth.contract( address=contract_address, abi=compiled_contracts["MerkleDrop"]["abi"]) token_contract = web3.eth.contract( address=merkle_drop_contract.functions.droppedToken().call(), abi=compiled_contracts["ERC20Interface"]["abi"], ) return { "address": to_checksum_address(merkle_drop_contract.address), "root": merkle_drop_contract.functions.root().call(), "decay_start_time": merkle_drop_contract.functions.decayStartTime().call(), "decay_duration_in_seconds": merkle_drop_contract.functions.decayDurationInSeconds().call(), "initial_balance": merkle_drop_contract.functions.initialBalance().call(), "remaining_value": merkle_drop_contract.functions.remainingValue().call(), "spent_tokens": merkle_drop_contract.functions.spentTokens().call(), "token_address": to_checksum_address(token_contract.address), "token_name": token_contract.functions.name().call(), "token_symbol": token_contract.functions.symbol().call(), "token_decimals": token_contract.functions.decimals().call(), "token_balance": token_contract.functions.balanceOf( merkle_drop_contract.address).call(), "decayed_remaining_value": merkle_drop_contract.functions.decayedEntitlementAtTime( merkle_drop_contract.functions.remainingValue().call(), pendulum.now().int_timestamp, True, ).call(), }
def token_contract(premint_token_value): web3 = connect_to_json_rpc("test") compiled_contracts = load_contracts_json("merkle_drop") token_contract: Contract = deploy_compiled_contract( abi=compiled_contracts["DroppedToken"]["abi"], bytecode=compiled_contracts["DroppedToken"]["bytecode"], constructor_args=( "Test Token", "TT", 18, web3.eth.accounts[0], premint_token_value, ), web3=web3, ) return token_contract
def unfunded_merkle_drop_contract( premint_token_value, root_hash_for_tree_data, token_contract ): web3 = connect_to_json_rpc("test") compiled_contracts = load_contracts_json("merkle_drop") merkle_drop_contract: Contract = deploy_compiled_contract( abi=compiled_contracts["MerkleDrop"]["abi"], bytecode=compiled_contracts["MerkleDrop"]["bytecode"], constructor_args=( token_contract.address, premint_token_value, root_hash_for_tree_data, pendulum.now().int_timestamp + 10, 60 * 60 * 24 * 4, ), web3=web3, ) return merkle_drop_contract
def deploy_validator_set_contract( *, web3, transaction_options: Dict = None, private_key=None ): if transaction_options is None: transaction_options = {} compiled_contracts = load_contracts_json(__name__) validator_set_abi = compiled_contracts["ValidatorSet"]["abi"] validator_set_bin = compiled_contracts["ValidatorSet"]["bytecode"] validator_set_contract: Contract = deploy_compiled_contract( abi=validator_set_abi, bytecode=validator_set_bin, web3=web3, transaction_options=transaction_options, private_key=private_key, ) return validator_set_contract
def deploy_validator_proxy_contract( *, web3, transaction_options: Dict = None, private_key=None, validators ): if transaction_options is None: transaction_options = {} compiled_contracts = load_contracts_json(__name__) validator_proxy_abi = compiled_contracts["ValidatorProxy"]["abi"] validator_proxy_bin = compiled_contracts["ValidatorProxy"]["bytecode"] validator_proxy_contract: Contract = deploy_compiled_contract( abi=validator_proxy_abi, bytecode=validator_proxy_bin, web3=web3, transaction_options=transaction_options, private_key=private_key, constructor_args=(validators,), ) return validator_proxy_contract
def deploy_merkle_drop( *, web3, transaction_options: Dict = None, private_key=None, constructor_args ): if transaction_options is None: transaction_options = {} compiled_contracts = load_contracts_json(__name__) merkle_drop_abi = compiled_contracts["MerkleDrop"]["abi"] merkle_drop_bin = compiled_contracts["MerkleDrop"]["bytecode"] merkle_drop_contract: Contract = deploy_compiled_contract( abi=merkle_drop_abi, bytecode=merkle_drop_bin, constructor_args=constructor_args, web3=web3, transaction_options=transaction_options, private_key=private_key, ) return merkle_drop_contract
def get_deployed_auction_contracts( web3, auction_address: str) -> DeployedAuctionContracts: compiled_contracts = load_contracts_json(__name__) auction_abi = compiled_contracts["BaseValidatorAuction"]["abi"] locker_abi = compiled_contracts["BaseDepositLocker"]["abi"] slasher_abi = compiled_contracts["ValidatorSlasher"]["abi"] auction = web3.eth.contract(address=auction_address, abi=auction_abi) locker_address = auction.functions.depositLocker().call() locker = web3.eth.contract(address=locker_address, abi=locker_abi) slasher_address = locker.functions.slasher().call() if slasher_address == ZERO_ADDRESS: slasher = None else: slasher = web3.eth.contract(address=slasher_address, abi=slasher_abi) deployed_auction_contracts: DeployedAuctionContracts = DeployedAuctionContracts( locker, slasher, auction) return deployed_auction_contracts
def deploy_auction_contracts( *, web3, transaction_options: Dict = None, private_key=None, auction_options: AuctionOptions, already_deployed_contracts: DeployedContractsAddresses = DeployedContractsAddresses(), ) -> DeployedAuctionContracts: use_token = auction_options.token_address is not None if transaction_options is None: transaction_options = {} if (already_deployed_contracts.auction is not None and already_deployed_contracts.locker is None): raise ValueError( "Cannot deploy new locker if auction already deployed due to constructor of auction." ) compiled_contracts = load_contracts_json(__name__) deposit_locker_abi = (compiled_contracts["TokenDepositLocker"]["abi"] if use_token else compiled_contracts["ETHDepositLocker"]["abi"]) deposit_locker_bin = (compiled_contracts["TokenDepositLocker"]["bytecode"] if use_token else compiled_contracts["ETHDepositLocker"]["bytecode"]) validator_slasher_abi = compiled_contracts["ValidatorSlasher"]["abi"] validator_slasher_bin = compiled_contracts["ValidatorSlasher"]["bytecode"] auction_abi = (compiled_contracts["TokenValidatorAuction"]["abi"] if use_token else compiled_contracts["ETHValidatorAuction"]["abi"]) auction_bin = (compiled_contracts["TokenValidatorAuction"]["bytecode"] if use_token else compiled_contracts["ETHValidatorAuction"]["bytecode"]) if already_deployed_contracts.locker is not None: deposit_locker_contract: Contract = web3.eth.contract( abi=deposit_locker_abi, bytecode=deposit_locker_bin, address=already_deployed_contracts.locker, ) else: deposit_locker_contract = deploy_compiled_contract( abi=deposit_locker_abi, bytecode=deposit_locker_bin, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) if already_deployed_contracts.slasher is not None: validator_slasher_contract = web3.eth.contract( abi=validator_slasher_abi, bytecode=validator_slasher_bin, address=already_deployed_contracts.slasher, ) else: validator_slasher_contract = deploy_compiled_contract( abi=validator_slasher_abi, bytecode=validator_slasher_bin, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) if already_deployed_contracts.auction is not None: auction_contract: Contract = web3.eth.contract( abi=auction_abi, bytecode=auction_bin, address=already_deployed_contracts.auction, ) else: auction_constructor_args: Tuple = ( auction_options.start_price, auction_options.auction_duration, auction_options.minimal_number_of_participants, auction_options.maximal_number_of_participants, deposit_locker_contract.address, ) if use_token: auction_constructor_args += (auction_options.token_address, ) auction_contract = deploy_compiled_contract( abi=auction_abi, bytecode=auction_bin, web3=web3, constructor_args=auction_constructor_args, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) contracts = DeployedAuctionContracts(deposit_locker_contract, validator_slasher_contract, auction_contract) return contracts
def get_validator_contract(*, web3, address): validator_contract_abi = load_contracts_json(__name__)["ValidatorSet"]["abi"] return web3.eth.contract(address=address, abi=validator_contract_abi)
def deploy_auction_contracts( *, web3, transaction_options: Dict = None, private_key=None, auction_options: AuctionOptions, ) -> DeployedAuctionContracts: if transaction_options is None: transaction_options = {} compiled_contracts = load_contracts_json(__name__) deposit_locker_abi = compiled_contracts["DepositLocker"]["abi"] deposit_locker_bin = compiled_contracts["DepositLocker"]["bytecode"] validator_slasher_abi = compiled_contracts["ValidatorSlasher"]["abi"] validator_slasher_bin = compiled_contracts["ValidatorSlasher"]["bytecode"] auction_abi = compiled_contracts["ValidatorAuction"]["abi"] auction_bin = compiled_contracts["ValidatorAuction"]["bytecode"] deposit_locker_contract: Contract = deploy_compiled_contract( abi=deposit_locker_abi, bytecode=deposit_locker_bin, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) validator_slasher_contract = deploy_compiled_contract( abi=validator_slasher_abi, bytecode=validator_slasher_bin, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) auction_constructor_args = ( auction_options.start_price, auction_options.auction_duration, auction_options.minimal_number_of_participants, auction_options.maximal_number_of_participants, deposit_locker_contract.address, ) auction_contract: Contract = deploy_compiled_contract( abi=auction_abi, bytecode=auction_bin, web3=web3, constructor_args=auction_constructor_args, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) contracts = DeployedAuctionContracts(deposit_locker_contract, validator_slasher_contract, auction_contract) return contracts