def test_token_precision_validation(value, token_decimals): token = EthToken.from_namedtuple( Token('Test_token', 'TST', '0x123', token_decimals)) with pytest.raises(ValueError) as error: token.validate_precision(value) assert str( error.value ) == f'Test_token token supports at most {token_decimals} decimal places.'
def test_get_token_from_token_contract(infura_token): network = EthereumTestnet() token = network.get_token_from_token_contract('0x53E546387A0d054e7FF127923254c0a679DA6DBf') assert token == Token( name='BlockbustersTest', symbol='BBT', address='0x53E546387A0d054e7FF127923254c0a679DA6DBf', decimals=18, )
def get_token_from_token_contract(self, token_address: str) -> Optional[Token]: """ Getting information from token contract and creating Token. Smart contract is taken based on provided address """ token_address = self.unify_address(token_address) token_contract = self.web3.eth.contract(address=token_address, abi=ERC20_BASIC_ABI) concise = ConciseContract(token_contract) try: name = concise.name() symbol = concise.symbol() decimals = concise.decimals() logger.debug(f'Token get from contract with success') except (OverflowError, BadFunctionCallOutput): logger.warning(f'Unable to take token from address: {token_address}') return return Token(name, symbol, token_address, decimals)
def extract_tokens(self): links = [l for l in self.html.find('#ContentPlaceHolder1_divresult tbody tr h5 a')] for l in links: address = l.attrib['href'].replace('/token/', '') name, symbol = l.text[:-1].split(' (') decimals = self.get_token_precision(address) if not decimals: print_error(f'Cannot define the number of decimal places for {name} ({symbol}). Ignoring.') self.ignored.append(name) continue token = Token(name, symbol, Web3.toChecksumAddress(address), decimals) if symbol in self.symbols: print_error(f'Duplicate symbol {symbol} for token {name}. Ignoring.') self.ignored.append(token) continue elif name in self.names: print_error(f'Duplicate name {name} for token {symbol}. Ignoring.') self.ignored.append(token) continue self.tokens.append(token) self.symbols.add(symbol) self.names.add(name) print_section(f'Tokens counter: {len(self.tokens)}.')
def get_token_from_token_contract(self, token_address: str) -> Optional[Token]: ''' Getting information from token contract (remote) Args: token_address (str): address of the token contract Returns: Token, None: Ethereum Token namedtuple or None if there is something goes wrong Raises: RuntimeError: if name or symbol of the token is not defined. Example: >>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_token_from_token_contract('0x2c76B98079Bb5520FF4BDBC1bf5012AC3E87ddF6') Token(name='PrettyGoodToken', symbol='PGT', address='0x2c76B98079Bb5520FF4BDBC1bf5012AC3E87ddF6', decimals=18) # noqa: E501 ''' token_address = self.unify_address(token_address) token_contract = self.web3.eth.contract(address=token_address, abi=ERC20_BASIC_ABI) concise = ConciseContract(token_contract) try: name = concise.name() symbol = concise.symbol() decimals = concise.decimals() if name == '' or symbol == '': raise RuntimeError( 'Unable to extract token details from token contract') logger.debug(f'Token get from contract with success') except (OverflowError, BadFunctionCallOutput): logger.warning( f'Unable to take token from address: {token_address}') return return Token(name, symbol, token_address, decimals)
from clove.network.ethereum_based import Token kovan_tokens = ( Token('BlockbustersTest', 'BBT', '0x53E546387A0d054e7FF127923254c0a679DA6DBf', 18), Token('PrettyGoodToken', 'PGT', '0x2c76B98079Bb5520FF4BDBC1bf5012AC3E87ddF6', 18), )
from clove.network.ethereum_based import Token tokens = ( Token('1World', '1WO', '0xfDBc1aDc26F0F8f8606a5d63b7D3a3CD21c22B23', 8), Token('300 Token', '300', '0xaEc98A708810414878c3BCDF46Aad31dEd4a4557', 18), Token('Accelerator', 'ACC', '0x13F1b7FDFbE1fc66676D56483e21B1ecb40b58E2', 18), Token('AdBank', 'ADB', '0x2baac9330Cf9aC479D819195794d79AD0c7616e3', 18), Token('AdEx', 'ADX', '0x4470BB87d77b963A013DB939BE332f927f2b992e', 4), Token('AdToken', 'ADT', '0xD0D6D6C5Fe4a677D343cC433536BB717bAe167dD', 9), Token('Aeron', 'ARN', '0xBA5F11b16B155792Cf3B2E6880E8706859A8AEB6', 8), Token('Aeternity', 'AE', '0x5CA9a71B1d01849C0a95490Cc00559717fCF0D1d', 18), Token('AidCoin', 'AID', '0x37E8789bB9996CaC9156cD5F5Fd32599E6b91289', 18), Token('Aigang', 'AIX', '0x1063ce524265d5a3A624f4914acd573dD89ce988', 18), Token('AION', 'AION', '0x4CEdA7906a5Ed2179785Cd3A40A69ee8bc99C466', 8), Token('AirSwap', 'AST', '0x27054b13b1B798B345b591a4d22e6562d47eA75a', 4), Token('AirToken', 'AIR', '0x27Dce1eC4d3f72C3E457Cc50354f1F975dDEf488', 8), Token('Alis', 'ALIS', '0xEA610B1153477720748DC13ED378003941d84fAB', 18), Token('All Sports Coin', 'SOC', '0x2d0E95bd4795D7aCe0da3C0Ff7b706a5970eb9D3', 18), Token('Amber', 'AMB', '0x4DC3643DbC642b72C158E7F3d2ff232df61cb6CE', 18), Token('AppCoins', 'APPC', '0x1a7a8BD9106F2B8D977E08582DC7d24c723ab0DB', 18), Token('Aragon', 'ANT', '0x960b236A07cf122663c4303350609A66A7B288C0', 18), Token('ArbitrageCT', 'ARCT', '0x1245ef80F4d9e02ED9425375e8F649B9221b31D8', 8), Token('Arcade', 'ARC', '0xAc709FcB44a43c35F0DA4e3163b117A17F3770f5', 18), Token('ArcBlock', 'ABT', '0xB98d4C97425d9908E66E53A6fDf673ACcA0BE986', 18), Token('AstroTokens', 'ASTRO', '0x7B22938ca841aA392C93dBB7f4c42178E3d65E88', 4), Token('ATLANT', 'ATL', '0x78B7FADA55A64dD895D8c8c35779DD8b67fA8a05', 18), Token('ATMChain', 'ATM', '0x9B11EFcAAA1890f6eE52C6bB7CF8153aC5d74139', 8), Token('Aurora DAO', 'AURA', '0xCdCFc0f66c522Fd086A1b725ea3c0Eeb9F9e8814', 18), Token('Authorship', 'ATS', '0x2dAEE1AA61D60A252DC80564499A69802853583A', 4), Token('AVT', 'AVT', '0x0d88eD6E74bbFD96B831231638b66C05571e824F', 18), Token('aXpire', 'AXP', '0x9af2c6B1A28D3d6BC084bd267F70e90d49741D5B', 8),
from clove.network.ethereum_based import Token kovan_tokens = (Token('BlockbustersTest', 'BBT', '0x53E546387A0d054e7FF127923254c0a679DA6DBf', 18), )