credmark.cmf.types.token_erc20.TokenInfo
- DTO class TokenInfo(*args, address, meta)[source]
Bases:
Token
Subclass of Token containing its related metadata.
Show JSON schema
{ "title": "TokenInfo", "description": "Subclass of Token containing its related metadata.", "type": "object", "properties": { "address": { "title": "Address", "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$", "format": "evm-address" }, "meta": { "$ref": "#/definitions/TokenMetadata" } }, "required": [ "address", "meta" ], "examples": [ { "address": "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9" }, { "symbol": "AAVE" }, { "address": "0x1F98431c8aD98523631AE4a59f267346ea31F984" }, { "address": "0x1F98431c8aD98523631AE4a59f267346ea31F984", "abi": "(Optional) contract abi JSON string or list" } ], "definitions": { "Contract": { "title": "Contract", "description": "Contract object to make web3 call smart contract functions.\nYou could create a contract with the following\n\n c = Contract(address='0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')\n\n c = Contract('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')", "type": "object", "properties": { "address": { "title": "Address", "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$", "format": "evm-address" } }, "required": [ "address" ], "examples": [ { "address": "0x1F98431c8aD98523631AE4a59f267346ea31F984" }, { "address": "0x1F98431c8aD98523631AE4a59f267346ea31F984", "abi": "(Optional) contract abi JSON string or list" } ] }, "TokenMetadata": { "title": "TokenMetadata", "type": "object", "properties": { "contract_name": { "title": "Contract Name", "type": "string" }, "deploy_tx_hash": { "title": "Deploy Tx Hash", "type": "string" }, "constructor_args": { "title": "Constructor Args", "type": "string" }, "abi_hash": { "title": "Abi Hash", "type": "string" }, "abi": { "title": "Abi", "type": "array", "items": {} }, "is_transparent_proxy": { "title": "Is Transparent Proxy", "type": "boolean" }, "proxy_implementation": { "$ref": "#/definitions/Contract" }, "deployed_block_number": { "title": "Deployed Block Number", "type": "integer" }, "symbol": { "title": "Symbol", "type": "string" }, "name": { "title": "Name", "type": "string" }, "decimals": { "title": "Decimals", "type": "integer" }, "total_supply": { "title": "Total Supply", "type": "integer" }, "wrapped": { "title": "Wrapped", "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$", "format": "evm-address" }, "set_loaded": { "title": "Set Loaded", "default": false, "type": "boolean" } } } } }
- Config
schema_extra: dict = {‘examples’: [{‘address’: ‘0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9’}, {‘symbol’: ‘AAVE’}, {‘address’: ‘0x1F98431c8aD98523631AE4a59f267346ea31F984’}, {‘address’: ‘0x1F98431c8aD98523631AE4a59f267346ea31F984’, ‘abi’: ‘(Optional) contract abi JSON string or list’}]}
- Fields
- Parameters
address (Address) –
meta (TokenMetadata) –
- Return type
None
- field address: Address [Required]
- Constraints
type = string
pattern = ^0x[a-fA-F0-9]{40}$
format = evm-address
- field meta: TokenMetadata [Required]
- DTO class ContractMetaData(*, contract_name=None, deploy_tx_hash=None, constructor_args=None, abi_hash=None, abi=None, is_transparent_proxy=None, proxy_implementation=None, deployed_block_number=None)
Bases:
BaseModel
Show JSON schema
{ "title": "ContractMetaData", "type": "object", "properties": { "contract_name": { "title": "Contract Name", "type": "string" }, "deploy_tx_hash": { "title": "Deploy Tx Hash", "type": "string" }, "constructor_args": { "title": "Constructor Args", "type": "string" }, "abi_hash": { "title": "Abi Hash", "type": "string" }, "abi": { "title": "Abi", "type": "array", "items": {} }, "is_transparent_proxy": { "title": "Is Transparent Proxy", "type": "boolean" }, "proxy_implementation": { "title": "Proxy Implementation" }, "deployed_block_number": { "title": "Deployed Block Number", "type": "integer" } } }
- Fields
abi (Optional[credmark.cmf.types.abi.ABI])
abi_hash (Optional[str])
constructor_args (Optional[str])
contract_name (Optional[str])
deploy_tx_hash (Optional[str])
deployed_block_number (Optional[credmark.cmf.types.block_number.BlockNumber])
is_transparent_proxy (Optional[bool])
proxy_implementation (Optional[Contract])
- Parameters
- Return type
None
- field deployed_block_number: Optional[BlockNumber] = None
- DTO class TokenMetadata(*, contract_name=None, deploy_tx_hash=None, constructor_args=None, abi_hash=None, abi=None, is_transparent_proxy=None, proxy_implementation=None, deployed_block_number=None, symbol=None, name=None, decimals=None, total_supply=None, wrapped=None, set_loaded=False)
Bases:
ContractMetaData
Show JSON schema
{ "title": "TokenMetadata", "type": "object", "properties": { "contract_name": { "title": "Contract Name", "type": "string" }, "deploy_tx_hash": { "title": "Deploy Tx Hash", "type": "string" }, "constructor_args": { "title": "Constructor Args", "type": "string" }, "abi_hash": { "title": "Abi Hash", "type": "string" }, "abi": { "title": "Abi", "type": "array", "items": {} }, "is_transparent_proxy": { "title": "Is Transparent Proxy", "type": "boolean" }, "proxy_implementation": { "$ref": "#/definitions/Contract" }, "deployed_block_number": { "title": "Deployed Block Number", "type": "integer" }, "symbol": { "title": "Symbol", "type": "string" }, "name": { "title": "Name", "type": "string" }, "decimals": { "title": "Decimals", "type": "integer" }, "total_supply": { "title": "Total Supply", "type": "integer" }, "wrapped": { "title": "Wrapped", "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$", "format": "evm-address" }, "set_loaded": { "title": "Set Loaded", "default": false, "type": "boolean" } }, "definitions": { "Contract": { "title": "Contract", "description": "Contract object to make web3 call smart contract functions.\nYou could create a contract with the following\n\n c = Contract(address='0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')\n\n c = Contract('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')", "type": "object", "properties": { "address": { "title": "Address", "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$", "format": "evm-address" } }, "required": [ "address" ], "examples": [ { "address": "0x1F98431c8aD98523631AE4a59f267346ea31F984" }, { "address": "0x1F98431c8aD98523631AE4a59f267346ea31F984", "abi": "(Optional) contract abi JSON string or list" } ] } } }
- Fields
abi (Optional[ABI])
abi_hash (Optional[str])
constructor_args (Optional[str])
contract_name (Optional[str])
decimals (Optional[int])
deploy_tx_hash (Optional[str])
deployed_block_number (Optional[BlockNumber])
is_transparent_proxy (Optional[bool])
name (Optional[str])
proxy_implementation (Optional['Contract'])
set_loaded (bool)
symbol (Optional[str])
total_supply (Optional[int])
wrapped (Optional[credmark.cmf.types.address.Address])
- Parameters
deployed_block_number (Optional[BlockNumber]) –
set_loaded (bool) –
- Return type
None
- field deployed_block_number: Optional[BlockNumber] = None
- field proxy_implementation: Optional['Contract'] = None
- field wrapped: Optional[Address] = None
- Constraints
type = string
pattern = ^0x[a-fA-F0-9]{40}$
format = evm-address
- get_cache(field, chain_id, block_number)
- update_cache(field, chain_id, block_number, value)
- as_erc20(set_loaded=False, use_alt=False)
- balance_of(address)
- balance_of_scaled(address)
- fetch_events(event, argument_filters=None, from_block=None, to_block=None, address=None, topics=None, contract_address=None, argument_names=None, by_range=None, use_async=False, async_worker=10)
contract_address is by default set to the event’s address.
For proxy contract, the event could be from the proxy contract and contract_address could be overridden with the contract’s address.
For example,
tok = Token(‘AAVE’) list(tok.fetch_events(
tok.proxy_for.events.Transfer, from_block=16_000_000, to_block=16_010_000, contract_address=tok.address))
For non-proxy contract, we may use as following
tok = Token(‘CRV’) df = pd.DataFrame(tok.fetch_events(
tok.events.Transfer, from_block=16_000_000, to_block=16_001_000, topics=[‘0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef’]))
df.loc[:, [‘blockNumber’, ‘_from’, ‘_to’, ‘_value’]]
- to_accounts()
- try_erc20_property(prop_name)
- classmethod validate(value)
- property abi
The ABI for the contract, if it’s available, otherwise None.
- property constructor_args
Constructor args, if any, otherwise None.
- property contract_name
Name of the contract, if available, otherwise None.
- property deploy_tx_hash
The deploy transaction hash, if available, otherwise None.
- property deployed_block_number
- property events
A web3 ContractEvents instance for the contract.
- property functions
A web3 ContractFunctions instance for the contract.
- property info
- property instance: Contract
A web3 Web3Contract instance or raises a
ModelDataError
if no ABI is available.
- property is_transparent_proxy
True if is a transparent proxy. Otherwise False or None.
- property models
- property proxy_for
A proxy implementation if available