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

feat(protocol-kit): Refactor and improve contract classes for Abitype #758

Conversation

tmjssz
Copy link
Contributor

@tmjssz tmjssz commented Apr 4, 2024

What it solves

Various code improvements to reduce duplicate code:

  • Move the following functions to higher class abstraction levels, instead of redefining them for every single contract + version + adapter:
    • getAddress
    • estimateGas
    • encode
  • Use basic ContractFunction type in all contract implementations
  • Add JS docs to all contract functions

How this PR fixes it

Changing the abstraction order of the contract classes: abstract at adapter level before abstracting at contract-level. This allows to move the getAddress, encode + estimateGas functions into the abstract adapter-level classes (e.g. BaseContractEthers) instead of defining them for each contract individually.

Introducing the BaseContract class to handle the logic of selecting the appropriate ABI and the address from contract deployments. This new class replaces all the contract-specific base classes, such as SafeBaseContract.

tmjssz added 11 commits April 2, 2024 17:18
* change the abstraction order: abstract at adapter level before abstracting at contract-level
* this allows to move the getAddress function into the abstract adapter-level classes instead of defining it for each contract individually
* introduce BaseContract class for appropriate ABI and the address from contract deployments
Move simulate and encode functions into higher class abstraction levels instead of defining it for every contract version individually
Move encode, estimateGas + getAddress functions into abstract parent classes.
Move encode, estimateGas + getAddress functions into abstract parent classes.
Move encode + getAddress functions into abstract parent classes.
Move encode + getAddress functions into abstract parent classes.
Use the new type in EncodeFunction, EstimateGasFunction + ContractFunction types
Move encode, estimateGas + getAddress functions into abstract parent classes.
Move encode, estimateGas + getAddress functions into abstract parent classes.
@tmjssz tmjssz requested review from dasanra and DaniSomoza April 4, 2024 15:01
@dasanra dasanra merged commit f33a4d0 into Abitype-CompatibilityFallbackHandler-contract Apr 5, 2024
12 of 14 checks passed
@dasanra dasanra deleted the Refactor-abitype-abstract-contract-classes branch April 5, 2024 10:11
@github-actions github-actions bot locked and limited conversation to collaborators Apr 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants