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): Add Abitype for contract types and use EIP-1193 #604

Merged
merged 201 commits into from May 16, 2024

Conversation

DaniSomoza
Copy link
Contributor

@DaniSomoza DaniSomoza commented Nov 24, 2023

What it solves

Resolves #582

Contracts Implemented

  • Safe Contract v1.4.1 Ethers.js & Web3.js
  • Safe Contract v1.3.0 Ethers.js & Web3.js
  • Safe Contract v1.2.0 Ethers.js & Web3.js
  • Safe Contract v1.1.1 Ethers.js & Web3.js
  • Safe Contract v1.0.0 Ethers.js & Web3.js
  • MultiSend Contract
  • MultiSendCallOnly Contract
  • ProxyFactory Contract
  • SignMessage Contract
  • SimulateTxAccessor Contract
  • CreateCall Contract
  • CompabilityFallbackHandler Contract

How this PR fixes it

Diagram5_SafeContracts

Classes And Types Implemented

  • Type SafeBaseContract: This Type uses abitype utilities to extract The Functions and Types from a given Abi.
  • Type SafeContract_v1_3_0_Contract: This Type uses the SafeBaseContract utility to extract The Functions and Types for a Safe contract version 1.3.0.
  • SafeBaseContract: Abstract class that serves as a base for creating a Safe contract for a specific adapter (Ethers.js, Web3.js, or viem.js). This class is designed to be extended by adapter-specific abstract classes, such as SafeBaseContractEthers (Implemented), SafeBaseContractWeb3 (pending implementation), and SafeBaseContractViem (pending implementation). It includes the core logic for selecting the appropriate ABI and the address from Safe deployments and determining the correct L1 or L2 contract version of the Safe.
  • SafeBaseContractEthers: This Abstract class extends SafeBaseContract to specifically integrate with the Ethers.js v6 library. This abstract class sets up the Ethers v6 Contract object that interacts with a Safe contract version. Subclasses of SafeBaseContractEthers are expected to represent specific versions of the Safe contract. Example subclasses: SafeContract_v1_4_1_Ethers (pending implementation), SafeContract_v1_3_0_Ethers (Implemented), SafeContract_v1_2_0_Ethers (pending implementation)...
  • SafeContract_v1_3_0_Ethers: This class specializes in handling interactions with the Safe contract version 1.3.0 using Ethers.js v6. Inherits from SafeBaseContractEthers and Implements the SafeContract_v1_3_0_Contract

Guides

Add a v1.4.1 Safe Contract For Ethers.js (Easy)

  1. Create Types for the v1.4.1 Safe contract: Create a SafeContract_v1_4_1.ts file in packages/protocol-kit/src/contracts/AbiType/Safe/v1.4.1/SafeContract_v1_4_1.ts. Use the implemented SafeContract_v1_3_0.ts as a model.
  2. Create SafeContract_v1_4_1_Ethers Class: Create a SafeContract_v1_4_1_Ethers.ts file in packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Ethers.ts. Use the implemented SafeContract_v1_3_0_Ethers.ts as a model.
  3. Update the contractInstancesEthers.ts file to use the new class.
  4. Remove the old SafeContract_V1_4_1_Ethers.ts
  5. Update the generateTypechainFiles.ts script to remove the generation of the Safe Contract v1.4.1 For Ethers.js.

Add Web3.js for v1.3.0 Safe Contract (Medium)

  1. Create a SafeBaseContractWeb3: Create a SafeBaseContractWeb3.ts file in packages/protocol-kit/src/adapters/web3/contracts/Safe/SafeBaseContractWeb3.ts. Use the implemented SafeBaseContractEthers.ts as a model.
  2. Create a SafeContract_v1_3_0_Web3: Create a SafeContract_v1_3_0_Web3.ts file in packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Web3.ts`.
  3. Update the contractInstancesEthers.ts file to use the new class.
  4. Remove the old SafeContract_V1_3_0_Web3.ts
  5. Update the generateTypechainFiles.ts script to remove the generation of the Safe Contract v1.3.0 For Web3.js.

Add another contract like safeProxyFactory v1.3.0 contract for Ethers (Hard):

  1. Create a safeProxyFactoryContract.ts types file. In the packages/protocol-kit/src/contracts/AbiType create a safeProxyFactoryContract.ts types using the Abi of the contract. See the implemented SafeBaseContract.ts file.
  2. Create a safeProxyFactoryBaseContract.ts in 'src/adapters' see src/adapters/SafeBaseContract.ts file as example.
  3. Create a safeProxyFactoryBaseContractEthers.ts see src/adapters/ethers/contracts/Safe/SafeBaseContractEthers.ts as example.
  4. Create a safeProxyFactory_v1_3_0_Ethers.ts: see the SafeContract_v1_3_0_Ethers file as example.
  5. Update the contractInstancesEthers.ts file to use the new class.
  6. Remove the old safeProxyFactory_V1_3_0_Ethers.ts
  7. Update the generateTypechainFiles.ts script to remove the generation of the safeProxyFactory v1.3.0 For Ethers.js.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 6979367114

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+22.9%) to 100.0%

Totals Coverage Status
Change from base Build 6972470735: 22.9%
Covered Lines: 25
Relevant Lines: 25

💛 - Coveralls

@coveralls
Copy link

coveralls commented Nov 24, 2023

Pull Request Test Coverage Report for Build 8452514007

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 5 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.9%) to 73.632%

Files with Coverage Reduction New Missed Lines %
packages/api-kit/src/SafeApiKit.ts 5 61.48%
Totals Coverage Status
Change from base Build 8099779389: -0.9%
Covered Lines: 476
Relevant Lines: 597

💛 - Coveralls

@DaniSomoza DaniSomoza changed the title Add abitype feat(protocol-kit): Add Abitype for Safe Contract v1.3.0 and Ethers Nov 24, 2023
@DaniSomoza DaniSomoza linked an issue Nov 24, 2023 that may be closed by this pull request
tmjssz and others added 2 commits December 13, 2023 14:53
* Create abstract class `SafeBaseContractWeb3`

* Implement class `SafeContract_v1_3_0_Web3`

* feat(protocol-kit): Add Abitype for Safe Contract 1.4.1 + Web3.js (#637)

* Create Types for the v1.4.1 Safe contract

* Implement class `SafeContract_v1_4_1_Web3`
…624)

* Create Types for the v1.4.1 Safe contract

* Create `SafeContract_v1_4_1_Ethers` Class

* feat(protocol-kit): Add Abitype for Safe Contract v1.2.0 + ethers.js (#627)

* Create Types for the v1.2.0 Safe contract

* Create `SafeContract_v1_2_0_Ethers` Class

* Add arg names to contract functions

---------

Co-authored-by: Daniel Somoza <daniel.somoza@safe.global>
* Rename old 1.1.1 Safe contract implementations (for Ethers.js + Web3.js)

* Create Types for the v1.1.1 Safe contract

* Implement `SafeContract_v1_1_1_Web3` class

* Implement `SafeContract_v1_1_1_Ethers` class

* Various fixes in Safe contract v1.1.1 implementations

* Update `contractInstancesEthers.ts` to use the new class

* Update `contractInstancesWeb3.ts` to use the new class

* Remove contract 1.1.1 from typechain generation script

* Remove old SafeContract v1.1.1 implementations

* Fix `getModulesPaginated` function in 1.1.1 contract implementations

* Fix binding issues in `mapToTypechainContract` function for contract v1.1.1 implementations
…pe + Fixes (#644)

* Rename old Safe contract v1.2.0 Web3 implementation

* Implement new `SafeContract_v1_2_0_Web3` class

* Update `contractInstancesWeb3.ts` to use the new class

* Remove contract 1.2.0 from typechain generation script

* Remove old SafeContract v1.2.0 implementation

* Move typechain mapper functions to individual Safe contract implementations for ethers.js

* Call `getModules` contract method directly for Safe contract v1.2.0

* fix: Handle return value of Safe contract's `getModulesPaginated` method correctly

* Fix `getMessageHash` return value in SafeContract_v1_2_0_Ethers

* Refactor `getModules` method in SafeContract classes

* Fix binding issues in typechain mapper functions for Safe contract v1.3.0 + v1.4.1
packages/protocol-kit/src/SafeProvider.ts Show resolved Hide resolved
packages/api-kit/tests/e2e/addSafeDelegate.test.ts Outdated Show resolved Hide resolved
packages/protocol-kit/src/SafeProvider.ts Show resolved Hide resolved
packages/protocol-kit/src/SafeProvider.ts Outdated Show resolved Hide resolved
packages/protocol-kit/src/managers/contractManager.ts Outdated Show resolved Hide resolved
packages/protocol-kit/src/contracts/utils.ts Outdated Show resolved Hide resolved
packages/protocol-kit/src/SafeProvider.ts Show resolved Hide resolved
dasanra and others added 12 commits May 15, 2024 13:39
* remove API reference from api-kit and protocol-kit

* chore: update relay-kit information to refer ERC-4337

---------

Co-authored-by: Yago Pérez Vázquez <yago@safe.global>
…e-sdk into Abitype-1_3_0-safe-contract

# Conflicts:
#	packages/account-abstraction-kit/package.json
#	packages/api-kit/package.json
#	packages/auth-kit/package.json
#	packages/onramp-kit/package.json
#	packages/protocol-kit/package.json
#	packages/relay-kit/package.json
#	packages/safe-core-sdk-types/package.json
…-global/safe-core-sdk into Abitype-1_3_0-safe-contract

# Conflicts:
#	packages/safe-core-sdk-types/package.json
@dasanra dasanra merged commit 12dccb6 into development May 16, 2024
19 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 16, 2024
@dasanra dasanra deleted the Abitype-1_3_0-safe-contract branch May 16, 2024 12:24
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.

Use AbiType to type v1.3.0 contracts
6 participants