def get_create_single_transaction( cls, ledger_api: LedgerApi, contract_address: Address, deployer_address: Address, token_id: int, data: Optional[bytes] = b"", gas: int = 300000, ) -> JSONLike: """ Get the transaction to create a single token. :param ledger_api: the ledger API :param contract_address: the address of the contract :param deployer_address: the address of the deployer :param token_id: the token id for creation :param data: the data to include in the transaction :param gas: the gas to be used :return: the transaction object """ if ledger_api.identifier == EthereumApi.identifier: nonce = ledger_api.api.eth.getTransactionCount(deployer_address) instance = cls.get_instance(ledger_api, contract_address) tx = instance.functions.createSingle( deployer_address, token_id, data ).buildTransaction( { "gas": gas, "gasPrice": ledger_api.api.toWei("50", "gwei"), "nonce": nonce, } ) tx = ledger_api.update_with_gas_estimate(tx) return tx if ledger_api.identifier in [CosmosApi.identifier, FetchAIApi.identifier]: msg = { "create_single": { "item_owner": deployer_address, "id": str(token_id), "path": str(data), } } cosmos_api = cast(CosmosApi, ledger_api) tx = cosmos_api.get_handle_transaction( deployer_address, contract_address, msg, amount=0, tx_fee=0, gas=gas ) return tx raise NotImplementedError
def create_option( cls, ledger_api: LedgerApi, contract_address: str, deployer_address: str, amount: int, period: int, strike: int, type: int, data: Optional[bytes] = b"", gas: int = 300000, ) -> Dict[str, Any]: """ Get the transaction to create a single token. :param ledger_api: the ledger API :param contract_address: the address of the contract :param deployer_address: the address of the deployer :param token_id: the token id for creation :param data: the data to include in the transaction :param gas: the gas to be used :return: the transaction object """ # create the transaction dict nonce = ledger_api.api.eth.getTransactionCount(deployer_address) instance = cls.get_instance(ledger_api, contract_address) fee_estimate = instance.functions.fees(period, amount, strike, type).call() tx = instance.functions.create(period, amount, strike, type).buildTransaction({ "from": deployer_address, "value": fee_estimate[1], "nonce": nonce }) tx = ledger_api.update_with_gas_estimate(tx) return tx
def provide_liquidity( cls, ledger_api: LedgerApi, contract_address: str, deployer_address: str, args: list, data: Optional[bytes] = b"", gas: int = 300000, ) -> Dict[str, Any]: """ Get the transaction to create a single token. :param ledger_api: the ledger API :param contract_address: the address of the contract :param deployer_address: the address of the deployer :param token_id: the token id for creation :param data: the data to include in the transaction :param gas: the gas to be used :return: the transaction object """ # create the transaction dict nonce = ledger_api.api.eth.getTransactionCount(deployer_address) instance = cls.get_instance(ledger_api, contract_address) tx = instance.functions.provide(args[0]).buildTransaction({ "from": deployer_address, "value": args[0], "gas": gas, "gasPrice": ledger_api.api.toWei("50", "gwei"), "nonce": nonce, }) instance.functions.provide(args[0]).call({"value": args[0]}) tx = ledger_api.update_with_gas_estimate(tx) return tx
def get_deploy_transaction( cls, ledger_api: LedgerApi, deployer_address: str, **kwargs, ) -> Optional[JSONLike]: """ Get the transaction to create a batch of tokens. :param ledger_api: the ledger API :param deployer_address: the address of the deployer :param args: the price :param gas: the gas to be used :return: the transaction object """ gas = kwargs.get("gas") if isinstance(kwargs.get("gas"), int) else 60000000 args = kwargs.get("args") if isinstance(kwargs.get("args"), list) else [] contract_interface = cls.contract_interface.get( ledger_api.identifier, {}) nonce = ledger_api.api.eth.getTransactionCount(deployer_address) instance = ledger_api.get_contract_instance(contract_interface) constructed = instance.constructor(*args) data = constructed.buildTransaction()["data"] tx: JSONLike = { "from": deployer_address, # only 'from' address, don't insert 'to' address! "value": 0, # transfer as part of deployment "gas": gas, "gasPrice": gas, # TODO: refine "nonce": nonce, "data": data, } tx = ledger_api.update_with_gas_estimate(tx) return tx
def get_transfer_transaction( cls, ledger_api: LedgerApi, contract_address: Address, from_address: Address, receiver: Address, amount: int, gas: int = 0, ) -> None: """ Get transaction to transfer tokens to an account :param ledger_api: the ledger apis. :param contract_address: the contract address. :param from_address: the address of the sender. :param receiver: the address to which to transfer tokens. :param amount: the amount of tokens to transfer. :param gas: the gas limit for the transaction. :return: None """ if ledger_api.identifier == EthereumApi.identifier: nonce = ledger_api.api.eth.getTransactionCount(from_address) instance = cls.get_instance(ledger_api, contract_address) function = instance.functions.transfer intermediate = function(receiver, amount) tx = intermediate.buildTransaction({ "gas": gas, "gasPrice": ledger_api.api.toWei("50", "gwei"), "nonce": nonce, }) tx = ledger_api.update_with_gas_estimate(tx) return tx raise NotImplementedError
def get_approve_transaction( cls, ledger_api: LedgerApi, contract_address: Address, from_address: Address, spender: Address, amount: int, gas: int = 0, ) -> None: """ Get transaction to approve oracle client contract transactions on behalf of sender. :param ledger_api: the ledger apis. :param contract_address: the contract address. :param from_address: the address of the approver. :param spender: the address approved to spend on behalf of sender. :param amount: the amount approved to be spent. :param gas: the gas limit for the transaction. :return: None """ if ledger_api.identifier == EthereumApi.identifier: nonce = ledger_api.api.eth.getTransactionCount(from_address) instance = cls.get_instance(ledger_api, contract_address) function = instance.functions.approve intermediate = function(spender, amount) tx = intermediate.buildTransaction({ "gas": gas, "gasPrice": ledger_api.api.toWei("50", "gwei"), "nonce": nonce, }) tx = ledger_api.update_with_gas_estimate(tx) return tx raise NotImplementedError
def get_mint_batch_transaction( cls, ledger_api: LedgerApi, contract_address: Address, deployer_address: Address, recipient_address: Address, token_ids: List[int], mint_quantities: List[int], data: Optional[bytes] = b"", gas: int = 500000, ) -> JSONLike: """ Get the transaction to mint a batch of tokens. :param ledger_api: the ledger API :param contract_address: the address of the contract :param deployer_address: the address of the deployer :param recipient_address: the address of the recipient :param token_ids: the token ids :param mint_quantities: the quantity to mint for each token :param data: the data to include in the transaction :param gas: the gas to be used :return: the transaction object """ cls.validate_mint_quantities(token_ids, mint_quantities) if ledger_api.identifier == EthereumApi.identifier: nonce = ledger_api.api.eth.getTransactionCount(deployer_address) instance = cls.get_instance(ledger_api, contract_address) tx = instance.functions.mintBatch(recipient_address, token_ids, mint_quantities, data).buildTransaction({ "gas": gas, "gasPrice": ledger_api.api.toWei( "50", "gwei"), "nonce": nonce, }) tx = ledger_api.update_with_gas_estimate(tx) return tx if ledger_api.identifier in [ CosmosApi.identifier, FetchAIApi.identifier ]: tokens = [] for token_id, quantity in zip(token_ids, mint_quantities): tokens.append({"id": str(token_id), "value": str(quantity)}) msg = { "mint_batch": { "to_address": recipient_address, "data": str(data), "tokens": tokens, } } cosmos_api = cast(CosmosApi, ledger_api) tx = cosmos_api.get_handle_transaction(deployer_address, contract_address, msg, amount=0, tx_fee=0, gas=gas) return tx raise NotImplementedError