def approval_function(token: ERC20Token, spender_address: Address, spender_name: str): if token.allowance_of(Address(token.web3.eth.defaultAccount), spender_address) < Wad(2**128 - 1): logger = logging.getLogger("api") logger.info( f"Approving {spender_name} ({spender_address}) to access our {token.name()} directly" ) if not token.approve(spender_address).transact(): raise RuntimeError("Approval failed!")
def approval_function(token: ERC20Token, spender_address: Address, spender_name: str): if token.allowance_of(tx_manager.address, spender_address) < Wad(2**128 - 1): logger = logging.getLogger("api") logger.info( f"Approving {spender_name} ({spender_address}) to access our {token.name()}" f" via TxManager {tx_manager.address}") if not tx_manager.execute([], [ (token.approve(spender_address).invocation()) ]).transact(): raise RuntimeError("Approval failed!")