Skip to main content

Calculate apy, apr, and wallet information,... in decentralized applications.

Project description

defi-state-querier

Description

Return the asset list of an address in a blockchain. These assets are native token, tokens, nft, and the assets locked in protocols.

Requirement

  • Accuracy
  • Fastest speed
  • Post all requests in a call with maximum batch size and workers

Input

  • address: str (lower case or upper case)
  • block_number: int
  • chain_id: string. Eg: 0x1, 0x38
  • query: array
    • query_id: id of query
    • entity_id: token address, nft or id of protocols like aave-v2, compound, and pancakeswap-amm
    • query_type: one of keywords - token_balance, ntf_balance, deposit_borrow, protocol_reward, and protocol_apy.

Output

[
  {
    "query_id": "<query_id>",
    "entity_id": "<token_address>",
    "query_type": "token_balance",
    "token_balance": 173.84
  },
  {
    "query_id": "<query_id>",
    "entity_id": "<nft_address>",
    "query_type": "nft_balance",
    "nft_balance": 11
  },
  {
    "query_id": "<query_id>",
    "entity_id": "<protocol_id>",
    "query_type": "deposit_borrow",
    "deposit_borrow": {
      "<protocol_address>": {
        "<asset_address_1>": {
          "borrow_amount": 184.4,
          "deposit_amount": 331.5
        },
        "<asset_address_2>": {
          "borrow_amount": 184.4,
          "deposit_amount": 331.5
        }
      }
    }
  },
  {
    "query_id": "<query_id>",
    "entity_id": "<protocol_id>",
    "query_type": "protocol_reward",
    "protocol_reward": {
      "<reward_address>": {
        "amount": 1.4
      }
    }
  },
  {
    "query_id": "<query_id>",
    "entity_id": "<protocol_id>",
    "query_type": "protocol_apy",
    "protocol_apy": {
      "<protocol_address>": {
        "<asset_address_1>": {
          "total_deposit": 331.5,
          "total_borrow": 184.4,
          "deposit_apy": 0.051,
          "borrow_apy": 0.067,
        }
      }
    }
  }
]

Query state data

Preparation

Get some information of protocols in their github or documents.

[1] Create abi files having format like erc20 token abi or aave v3 lending abi.

[2] Get basic information of protocols and save in a python file like aave_v2_eth.py.

Infrastructure

Important files

[1] state_querier.py - create function information, encode function calls, push function calls, and decode response data.

[2] state_processor.py - receive input, combine all encoded function calls in a batch, execute function call batch, process response data, and return output.

[3] protocol_services.py - protocol service pattern file, all protocols should follow this file like aave_v2_services.py. There are 4 main functions of a service: get service info, get token list related to protocol, get asset information supported by protocol (dapp), get all information of function calls, and process response data.

[4] token_services.py - get information of erc 20 function calls and process response data.

Examples

[1] token_information.py - example of using state querier.

[2] wallet_information.py - example of using state processor.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

defi_state_querier-0.5.15.tar.gz (382.8 kB view details)

Uploaded Source

Built Distribution

defi_state_querier-0.5.15-py3-none-any.whl (616.5 kB view details)

Uploaded Python 3

File details

Details for the file defi_state_querier-0.5.15.tar.gz.

File metadata

  • Download URL: defi_state_querier-0.5.15.tar.gz
  • Upload date:
  • Size: 382.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for defi_state_querier-0.5.15.tar.gz
Algorithm Hash digest
SHA256 771fe22b72c4ad6a5ee49a3a8295376758f00bd2aed18eb3ba0a80f1d213c08e
MD5 5f19ff7ac94a0b5414ce9b95233af68d
BLAKE2b-256 a094375d36e707d9e8e46921129875d88f8de391b3962b051c3b22feac5c2204

See more details on using hashes here.

File details

Details for the file defi_state_querier-0.5.15-py3-none-any.whl.

File metadata

File hashes

Hashes for defi_state_querier-0.5.15-py3-none-any.whl
Algorithm Hash digest
SHA256 147335e1dfd9dc44a5f750347b3ff091c00d7c85edc3d48178532e96aed61358
MD5 8c0073af0b66c3b392b90d6e19754436
BLAKE2b-256 df6d59ad0b7b495f6d7405ef3cf6d839bcd2c7c76639194856177084bef37fe7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page