def payout_approve( config: BoardCommmadConfiguration, payout_token_address: str, payout_token_name: str, ): """ approve tokens to the payout contract """ from sto.ethereum.utils import (get_contract_deployed_tx, create_web3, get_abi, broadcast as _broadcast, priv_key_to_address) from sto.ethereum.txservice import EthereumStoredTXService from sto.models.implementation import BroadcastAccount, PreparedTransaction tx = get_contract_deployed_tx(config.dbsession, 'PayoutContract') if not tx: raise Exception( 'PayoutContract not found. Call payout-deploy to deploy PayoutContract' ) if payout_token_name: tx = get_contract_deployed_tx(config.dbsession, payout_token_name) payout_token_address = tx.contract_address if payout_token_address is None: raise Exception(''' Either payout token is not deployed or --payout-token-address not provided ''') tx = get_contract_deployed_tx(config.dbsession, 'PayoutContract') if not tx: raise Exception( 'PayoutContract not found. Call payout-deploy to deploy PayoutContract' ) payout_contract_address = tx.contract_address web3 = create_web3(config.ethereum_node_url) service = EthereumStoredTXService(config.network, config.dbsession, web3, config.ethereum_private_key, config.ethereum_gas_price, config.ethereum_gas_limit, BroadcastAccount, PreparedTransaction) abi = get_abi(config.ethereum_abi_file) payout_token_contract = web3.eth.contract( address=payout_token_address, abi=abi[payout_token_name]['abi']) service.interact_with_contract( payout_token_name, abi, payout_token_address, 'approving tokens', 'approve', args={ '_spender': payout_contract_address, '_value': payout_token_contract.functions.balanceOf( priv_key_to_address(config.ethereum_private_key)).call() }, use_bytecode=False) _broadcast(config)
def payout_dividends(config: BoardCommmadConfiguration, transfer_amount): from sto.ethereum.utils import (get_contract_deployed_tx, create_web3, get_abi, broadcast as _broadcast) from sto.ethereum.txservice import EthereumStoredTXService from sto.models.implementation import BroadcastAccount, PreparedTransaction tx = get_contract_deployed_tx(config.dbsession, 'PayoutContract') if not tx: raise Exception( 'PayoutContract not found. Call payout-deploy to deploy PayoutContract' ) web3 = create_web3(config.ethereum_node_url) service = EthereumStoredTXService(config.network, config.dbsession, web3, config.ethereum_private_key, config.ethereum_gas_price, config.ethereum_gas_limit, BroadcastAccount, PreparedTransaction) abi = get_abi(config.ethereum_abi_file) service.interact_with_contract( contract_name='PayoutContract', abi=abi, address=tx.contract_address, note='transferring amount: {0}'.format(transfer_amount), func_name='act', args={'amount': transfer_amount}) _broadcast(config)
def payout_deposit(config: BoardCommmadConfiguration): """ the private key here needs to belong to the customer who wants to fetch tokens """ from sto.ethereum.utils import (get_contract_deployed_tx, create_web3, get_abi, broadcast as _broadcast) from sto.ethereum.txservice import EthereumStoredTXService from sto.models.implementation import BroadcastAccount, PreparedTransaction tx = get_contract_deployed_tx(config.dbsession, 'PayoutContract') if not tx: raise Exception( 'PayoutContract not found. Call payout-deploy to deploy PayoutContract' ) web3 = create_web3(config.ethereum_node_url) service = EthereumStoredTXService(config.network, config.dbsession, web3, config.ethereum_private_key, config.ethereum_gas_price, config.ethereum_gas_limit, BroadcastAccount, PreparedTransaction) abi = get_abi(config.ethereum_abi_file) service.interact_with_contract(contract_name='PayoutContract', abi=abi, address=tx.contract_address, note='calling fetchTokens', func_name='fetchTokens', args={}) _broadcast(config)
def voting_deploy(config: BoardCommmadConfiguration, token_address, kyc_address, voting_name, uri, type, options): """ Deploys Voting contract to desired ethereum network network, ethereum-abi-file, ethereum-private-key, ethereum-node-url are required args """ from sto.ethereum.utils import deploy_contract, integer_hash, get_contract_deployed_tx from eth_utils import to_bytes if kyc_address is None: tx = get_contract_deployed_tx(config.dbsession, 'BasicKYC') if not tx: raise Exception( 'BasicKYC contract not deployed. Please call kyc-deploy') kyc_address = tx.contract_address args = { '_token': token_address, '_KYC': kyc_address, 'name': to_bytes(text=voting_name), 'URI': to_bytes(text=uri), '_type': type, '_hash': integer_hash(type), '_options': [to_bytes(i) for i in options] } deploy_contract(config, contract_name='VotingContract', constructor_args=args)
def payout_deploy(config: BoardCommmadConfiguration, token_address, payout_token_address, payout_token_name, kyc_address, payout_name, uri, type, options): """ Deploys Voting contract to desired ethereum network network, ethereum-abi-file, ethereum-private-key, ethereum-node-url are required args """ from sto.ethereum.utils import deploy_contract, integer_hash, get_contract_deployed_tx from eth_utils import to_bytes from sto.ethereum.utils import (get_contract_deployed_tx) if kyc_address is None: tx = get_contract_deployed_tx(config.dbsession, 'BasicKYC') if not tx: raise Exception('BasicKYC contract not deployed. Please call ') kyc_address = tx.contract_address if payout_token_name: tx = get_contract_deployed_tx(config.dbsession, payout_token_name) if not tx: raise Exception( '{0} contract not deployed.'.format(payout_token_name)) payout_token_address = tx.contract_address if payout_token_address is None: raise Exception(''' Either payout token is not deployed or --payout-token-address not provided ''') args = { '_token': token_address, '_payoutToken': payout_token_address, '_KYC': kyc_address, 'name': to_bytes(text=payout_name), 'URI': to_bytes(text=uri), '_type': type, '_hash': integer_hash(type), '_options': [to_bytes(text=i) for i in options] } deploy_contract(config, contract_name='PayoutContract', constructor_args=args)
def deploy_token_contracts( logger: Logger, dbsession: Session, network: str, ethereum_node_url: Union[str, Web3], ethereum_abi_file: Optional[str], ethereum_private_key: Optional[str], ethereum_gas_limit: Optional[int], ethereum_gas_price: Optional[int], name: str, symbol: str, url: str, amount: int, transfer_restriction: str): """Issue out a new Ethereum token.""" assert type(amount) == int decimals = 18 # Everything else is bad idea check_good_private_key(ethereum_private_key) abi = get_abi(ethereum_abi_file) web3 = create_web3(ethereum_node_url) service = EthereumStoredTXService(network, dbsession, web3, ethereum_private_key, ethereum_gas_price, ethereum_gas_limit, BroadcastAccount, PreparedTransaction) # Deploy security token note = "Deploying token contract for {}".format(name) deploy_tx1 = service.deploy_contract("SecurityToken", abi, note, constructor_args={ "_name": name, "_symbol": symbol, "_url": url }) # See SecurityToken.sol # Deploy transfer agent if transfer_restriction == "unrestricted": note = "Deploying unrestricted transfer policy for {}".format(name) deploy_tx2 = service.deploy_contract("UnrestrictedTransferAgent", abi, note) else: note = "Deploying restricted transfer policy for {}".format(name) tx = get_contract_deployed_tx(dbsession, 'BasicKYC') if not tx: raise Exception( 'BasicKyc contract is not deployed. ' 'invoke command kyc-deploy to deploy the smart contract') deploy_tx2 = service.deploy_contract( "RestrictedTransferAgent", abi, note, constructor_args={'_KYC': tx.contract_address}) # Set transfer agent note = "Making transfer restriction policy for {} effective".format(name) contract_address = deploy_tx1.contract_address update_tx1 = service.interact_with_contract( "SecurityToken", abi, contract_address, note, "setTransactionVerifier", {"newVerifier": deploy_tx2.contract_address}) # Issue out initial shares note = "Creating {} initial shares for {}".format(amount, name) contract_address = deploy_tx1.contract_address amount_18 = int(amount * 10**decimals) update_tx2 = service.interact_with_contract("SecurityToken", abi, contract_address, note, "issueTokens", {"value": amount_18}) logger.info("Prepared transactions for broadcasting for network %s", network) logger.info("STO token contract address will be %s%s%s", colorama.Fore.LIGHTGREEN_EX, deploy_tx1.contract_address, colorama.Fore.RESET) return [deploy_tx1, deploy_tx2, update_tx1, update_tx2]