Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying: allow block-series .query method on any ContractCall object #380

Open
4 tasks
fubuloubu opened this issue Jan 3, 2022 · 2 comments
Open
4 tasks
Labels
category: feature New feature or request size: 3 pieces Moderately challenging, well-defined, may require a bit of research

Comments

@fubuloubu
Copy link
Member

fubuloubu commented Jan 3, 2022

Elevator pitch:

Be able to form datasets from querying a view method in a contract over a specified range of blocks.

For example:

# Plot DAI's total supply over specified range of blocks
total_supply = dai.totalSupply.query(start_block=N, end_block=M)
plt.plot(range(N, M), total_supply // 10 ** dai.decimals())

# Plot DAI's % ownership of DAI in Uni v2 DAI/WETH pool over specified range of blocks
plt.plot(
    range(N, M),
    dai.balanceOf.query(uniswap_v2_dai_weth, start_block=N, end_block=M) // total_supply,
)
plt.show()

Value:

This is valuable for data scientists who quickly want to perform an efficient query over a range of blocks to obtain a timeseries dataset.

Dependencies:

In order to be efficient, significant caching is necessary, coupled with an archive node for historical retrieval. Explore making these types of queries as efficient as possible.

Design approach:

class ContractCall:
    def query(self, *args, **kwargs):
        # Encode the call w/ *args
        ...
        # Perform query using ProviderAPI over `kwargs` query args
        ...

class ContractCallContainer:
    def query(self, *args, **kwargs):
        # Figure out which `ContractCall` to route to
        ...
        return contract_caller(*args, **kwargs)

Task list:

  • Explore fundamental data model for query results (numpy?)
  • Explore ProviderAPI updates to make historical queries
  • Design kwargs specification for query filter parameters (e.g. start_block, end_block, etc.)
  • Explore QueryAPI updates to speed up historical queries

Estimated completion date:

Design review:

Do not signoff unless:

    1. agreed the tasks and design approach will achieve acceptance, and
    1. the work can be completed by one person within the SLA.
      Design reviewers should consider simpler approaches to achieve goals.

(Please leave a comment to sign off)

@fubuloubu
Copy link
Member Author

NOTE: Blocks are a natural way to conduct this type of query, because they are explicit. Timestamps sometimes are tricky to work with in this context (but should be explored regardless)

@fubuloubu
Copy link
Member Author

Related: #390

@fubuloubu fubuloubu added category: feature New feature or request size: 3 pieces Moderately challenging, well-defined, may require a bit of research labels Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: feature New feature or request size: 3 pieces Moderately challenging, well-defined, may require a bit of research
Projects
None yet
Development

No branches or pull requests

2 participants