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

Allow Plugins to customize ContractContainer and ContractType #818

Closed
1 task
antazoey opened this issue Jun 20, 2022 · 2 comments
Closed
1 task

Allow Plugins to customize ContractContainer and ContractType #818

antazoey opened this issue Jun 20, 2022 · 2 comments
Labels
category: feature New feature or request

Comments

@antazoey
Copy link
Member

antazoey commented Jun 20, 2022

Elevator pitch:

Deploying contracts and / or contract interaction can sometimes work differently, depending on the development environment (e.g. Starknet)

ape-starknet needs more customization around ContractContainers available on the ProjectManager (e.g. ape.project.MyContract).

We need to support contract declaration. Soon, Deploy transactions will no longer work on Starknet.
A contract declaration in Starknet is a type of transaction (like a Deploy) but for allowing other contracts to deploy your contract.
You cannot invoke methods on a ContractDeclaration. It like a Class versus an instance of the class. In Starknet, you publish your contract types and other contracts (accounts) can deploy those types.

Additionally, we would like to be able to customize the selector hash function of contract types, which is available in ethpm-types but there is not an easy way to force Ape to use a custom class of ContractType.

Value:

  • Ecosystem plugins
  • Multi-chain compatibility in Ape.
  • Starknet users

Dependencies:

n/a

Design approach:

ape.api.compilers.py:

class CompilerAPI:
    contract_type_cls: Type[ContracType] = ContractType
    """The class to use when creating contract types."""

CompilerManager in ape:

class CompilerManager:
    def lookup_contract_type_cls(self, contract_type):
        """Get the plugin defined contract type cls for a given contract type."""

new file: ape.api.contracts.py:

class ContractContainerAPI:
   @abstractmethod
   def is_container_type(self, contract_type: ContractType):
        ...

   @abstractmethod
   def get_container(self, contract_type) -> ContractContainer:
        ....
  

class ContractContainer:
   def is_container_type(self, contract_type: ContractType):
       """Return True when the contract type is part of a specific plugin's container type."""
       
   def get_container(self, contract_type) -> ContractContainer:
        plugin_defined_contract_type = self.compiler_manager.lookup_contract_type_cls(contract_type)
        return ContractContainer(plugin_defined_contract_type)

ape-cairo compilers.py:

class StarknetContractType(ContractType):
    """A contract type with a custom hash function using the Starknet keccak
         for easy lookup of contract methods."""
         
class CairoCompiler:
    contract_type_cls = StarknetContractType

ape-starknet register the container

from ape.api.contracts import ContractContainer

# Has all the same methods as the normal container except adding new ones (still a registerable API class)
class StarknetContractContainer(ContractContainer):
    def declare() -> ContractDelcaration (definiton TBD)

Task list:

  • Tasks go here

Estimated completion date:

For now, the plan to add declare() to the accounts, since we have deploy() there as well. However, it is more ideal to have both.

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)

Related Tickets

Contract declaration support: ApeWorX/archive-ape-starknet#32
Custom selector insurance: ApeWorX/ethpm-types#38
Custom contract types in ape-cairo: https://github.com/ApeWorX/ape-cairo/issues/20

@antazoey antazoey changed the title Allow Plugins to customize Contract Container Allow Plugins to customize ContractContainer and ContractType Jun 20, 2022
@antazoey
Copy link
Member Author

This is also something that is hinting might be a good ticket to do for titanboa enhancement.

My idea is something along the lines of allowing ape-vyper to customize ContractContainer objects for vyper contracts. I don't know exactly how that will work yet.

@fubuloubu

@NotPeopling2day NotPeopling2day added the category: feature New feature or request label Sep 6, 2022
@antazoey
Copy link
Member Author

antazoey commented Oct 30, 2023

No longer needed - declare is now part of official API.

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
Projects
None yet
Development

No branches or pull requests

2 participants