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
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 abi: Optional[ABI] = None
field abi_hash: Optional[str] = None
field constructor_args: Optional[str] = None
field contract_name: Optional[str] = None
field deploy_tx_hash: Optional[str] = None
field deployed_block_number: Optional[BlockNumber] = None
field is_transparent_proxy: Optional[bool] = None
field proxy_implementation: Optional[Contract] = 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
Return type

None

field abi: Optional[ABI] = None
field abi_hash: Optional[str] = None
field constructor_args: Optional[str] = None
field contract_name: Optional[str] = None
field decimals: Optional[int] = None
field deploy_tx_hash: Optional[str] = None
field deployed_block_number: Optional[BlockNumber] = None
field is_transparent_proxy: Optional[bool] = None
field name: Optional[str] = None
field proxy_implementation: Optional['Contract'] = None
field set_loaded: bool = False
field symbol: Optional[str] = None
field total_supply: Optional[int] = 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)
Parameters

address (Union[ChecksumAddress, str, bytes, Address]) –

Return type

int

balance_of_scaled(address)
Parameters

address (Union[ChecksumAddress, str, bytes, Address]) –

Return type

float

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’]]

Parameters
scaled(value)
Return type

float

set_abi(abi, set_loaded=False)

Set the ABI for the contract

Parameters

abi (Union[List, str]) –

to_accounts()
try_erc20_property(prop_name)
unscaled(value)
Return type

float

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 decimals: int
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 fiat: bool
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 ledger: None
property models
property name: str
property proxy_for

A proxy implementation if available

property symbol: str
property total_supply: int
property total_supply_scaled: float