safe-core-sdk icon indicating copy to clipboard operation
safe-core-sdk copied to clipboard

feat(protocol-kit): Add Abitype for Safe Contract v1.3.0 and Ethers

Open DaniSomoza opened this issue 7 months ago • 2 comments

What it solves

Resolves #582

Contracts Implemented

  • [x] Safe Contract v1.4.1 Ethers.js & Web3.js
  • [x] Safe Contract v1.3.0 Ethers.js & Web3.js
  • [x] Safe Contract v1.2.0 Ethers.js & Web3.js
  • [x] Safe Contract v1.1.1 Ethers.js & Web3.js
  • [x] Safe Contract v1.0.0 Ethers.js & Web3.js
  • [x] MultiSend Contract
  • [x] MultiSendCallOnly Contract
  • [x] ProxyFactory Contract
  • [x] SignMessage Contract
  • [x] SimulateTxAccessor Contract
  • [x] CreateCall Contract
  • [x] 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.

DaniSomoza avatar Nov 24 '23 10:11 DaniSomoza