safe-core-sdk
safe-core-sdk copied to clipboard
feat(protocol-kit): Add Abitype for Safe Contract v1.3.0 and Ethers
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
Classes And Types Implemented
- Type
SafeBaseContract
: This Type usesabitype
utilities to extract The Functions and Types from a given Abi. - Type
SafeContract_v1_3_0_Contract
: This Type uses theSafeBaseContract
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 asSafeBaseContractEthers
(Implemented),SafeBaseContractWeb3
(pending implementation), andSafeBaseContractViem
(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 extendsSafeBaseContract
to specifically integrate with theEthers.js v6
library. This abstract class sets up the Ethers v6 Contract object that interacts with a Safe contract version. Subclasses ofSafeBaseContractEthers
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 fromSafeBaseContractEthers
and Implements theSafeContract_v1_3_0_Contract
Guides
Add a v1.4.1
Safe Contract For Ethers.js
(Easy)
- Create Types for the
v1.4.1
Safe contract: Create aSafeContract_v1_4_1.ts
file inpackages/protocol-kit/src/contracts/AbiType/Safe/v1.4.1/SafeContract_v1_4_1.ts
. Use the implementedSafeContract_v1_3_0.ts
as a model. - Create
SafeContract_v1_4_1_Ethers
Class: Create aSafeContract_v1_4_1_Ethers.ts
file inpackages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Ethers.ts
. Use the implementedSafeContract_v1_3_0_Ethers.ts
as a model. - Update the
contractInstancesEthers.ts
file to use the new class. - Remove the old
SafeContract_V1_4_1_Ethers.ts
- Update the
generateTypechainFiles.ts
script to remove the generation of the Safe Contractv1.4.1
For Ethers.js.
Add Web3.js
for v1.3.0
Safe Contract (Medium)
- Create a
SafeBaseContractWeb3
: Create aSafeBaseContractWeb3.ts
file inpackages/protocol-kit/src/adapters/web3/contracts/Safe/SafeBaseContractWeb3.ts
. Use the implementedSafeBaseContractEthers.ts
as a model. - Create a
SafeContract_v1_3_0_Web3
: Create aSafeContract_v1_3_0_Web3.ts file in
packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Web3.ts`. - Update the
contractInstancesEthers.ts
file to use the new class. - Remove the old
SafeContract_V1_3_0_Web3.ts
- Update the
generateTypechainFiles.ts
script to remove the generation of the Safe Contractv1.3.0
For Web3.js.
Add another contract like safeProxyFactory
v1.3.0
contract for Ethers (Hard):
- Create a
safeProxyFactoryContract.ts
types file. In thepackages/protocol-kit/src/contracts/AbiType
create asafeProxyFactoryContract.ts
types using the Abi of the contract. See the implementedSafeBaseContract.ts
file. - Create a
safeProxyFactoryBaseContract.ts
in 'src/adapters' seesrc/adapters/SafeBaseContract.ts
file as example. - Create a
safeProxyFactoryBaseContractEthers.ts
seesrc/adapters/ethers/contracts/Safe/SafeBaseContractEthers.ts
as example. - Create a
safeProxyFactory_v1_3_0_Ethers.ts
: see theSafeContract_v1_3_0_Ethers
file as example. - Update the
contractInstancesEthers.ts
file to use the new class. - Remove the old
safeProxyFactory_V1_3_0_Ethers.ts
- Update the
generateTypechainFiles.ts
script to remove the generation of the safeProxyFactoryv1.3.0
For Ethers.js.