-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
4,314 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
contractName, | ||
safeDeploymentsL1ChainIds, | ||
getContractDeployment | ||
} from '@safe-global/protocol-kit/contracts/config' | ||
import { SafeVersion } from 'packages/safe-core-sdk-types' | ||
|
||
/** | ||
* Abstract class SafeBaseContract 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, SafeBaseContractWeb3, and SafeBaseContractViem. | ||
* 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. | ||
* | ||
* @template SafeContractAbiType - The ABI associated with the Safe contract. | ||
* | ||
* Example subclasses extending this base class: | ||
* - SafeBaseContractEthers<SafeContract_v1_3_0_Abi> extends SafeBaseContract<SafeContract_v1_3_0_Abi> | ||
* - SafeBaseContractWeb3<SafeContract_v1_3_0_Abi> extends SafeBaseContract<SafeContract_v1_3_0_Abi> | ||
* - SafeBaseContractViem<SafeContract_v1_3_0_Abi> extends SafeBaseContract<SafeContract_v1_3_0_Abi> | ||
*/ | ||
abstract class SafeBaseContract<SafeContractAbiType> { | ||
contractAbi: SafeContractAbiType | ||
contractAddress: string | ||
|
||
contractName: contractName | ||
abstract safeVersion: SafeVersion | ||
|
||
abstract contract: unknown // This needs to be implemented for each adapter. | ||
abstract adapter: unknown // This needs to be implemented for each adapter. | ||
|
||
/** | ||
* Constructs a new SafeBaseContract instance. | ||
* | ||
* @param chainId - The chain ID of the contract. | ||
* @param defaultAbi - The hardcoded ABI of the Safe contract. | ||
* @param safeVersion - The version of the Safe contract. | ||
* @param isL1SafeSingleton - Flag to indicate if it's an L1 Safe Singleton. | ||
* @param customContractAddress - Optional custom address for the contract. | ||
* @param customContractAbi - Optional custom ABI for the contract. | ||
* @throws Will throw an error if the contract address is invalid. | ||
*/ | ||
constructor( | ||
chainId: bigint, | ||
defaultAbi: SafeContractAbiType, | ||
safeVersion: SafeVersion, | ||
isL1SafeSingleton = false, | ||
customContractAddress?: string, | ||
customContractAbi?: SafeContractAbiType | ||
) { | ||
const isL1Contract = safeDeploymentsL1ChainIds.includes(chainId) || isL1SafeSingleton | ||
|
||
this.contractName = isL1Contract ? 'safeSingletonVersion' : 'safeSingletonL2Version' | ||
|
||
const singletonDeployment = getContractDeployment(safeVersion, chainId, this.contractName) | ||
|
||
const contractAddress = customContractAddress || singletonDeployment?.defaultAddress | ||
|
||
if (!contractAddress) { | ||
throw new Error('Invalid SafeProxy contract address') | ||
} | ||
|
||
this.contractAddress = contractAddress | ||
this.contractAbi = | ||
customContractAbi || | ||
(singletonDeployment?.abi as SafeContractAbiType) || // this cast is required because abi is set as any[] in safe-deployments | ||
defaultAbi // if no customAbi and no abi is present in the safe-deployments we use our hardcoded abi | ||
} | ||
} | ||
|
||
export default SafeBaseContract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/protocol-kit/src/adapters/ethers/contracts/Safe/SafeBaseContractEthers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Contract, InterfaceAbi } from 'ethers' | ||
|
||
import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' | ||
import { SafeVersion } from 'packages/safe-core-sdk-types' | ||
import SafeBaseContract from '@safe-global/protocol-kit/adapters/SafeBaseContract' | ||
|
||
/** | ||
* Abstract class SafeBaseContractEthers extends SafeBaseContract to specifically integrate with the Ethers.js v6 library. | ||
* It is designed to be instantiated for different versions of the Safe contract. | ||
* | ||
* 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. | ||
* | ||
* @template SafeContractAbiType - The ABI type specific to the version of the Safe contract, extending InterfaceAbi from Ethers. | ||
* @extends SafeBaseContract<SafeContractAbiType> - Extends the generic SafeBaseContract with Ethers-specific implementation. | ||
* | ||
* Example subclasses: | ||
* - SafeContract_v1_4_1_Ethers extends SafeBaseContractEthers<SafeContract_v1_4_1_Abi> | ||
* - SafeContract_v1_3_0_Ethers extends SafeBaseContractEthers<SafeContract_v1_3_0_Abi> | ||
* - SafeContract_v1_2_0_Ethers extends SafeBaseContractEthers<SafeContract_v1_2_0_Abi> | ||
* - SafeContract_v1_1_1_Ethers extends SafeBaseContractEthers<SafeContract_v1_1_1_Abi> | ||
* - SafeContract_v1_0_0_Ethers extends SafeBaseContractEthers<SafeContract_v1_0_0_Abi> | ||
*/ | ||
abstract class SafeBaseContractEthers< | ||
SafeContractAbiType extends InterfaceAbi | ||
> extends SafeBaseContract<SafeContractAbiType> { | ||
contract: Contract | ||
adapter: EthersAdapter | ||
|
||
/** | ||
* @constructor | ||
* Constructs an instance of SafeBaseContractEthers. | ||
* | ||
* @param chainId - The chain ID of the contract. | ||
* @param ethersAdapter - An instance of EthersAdapter. | ||
* @param defaultAbi - The default ABI for the Safe contract. It should be compatible with the specific version of the Safe contract. | ||
* @param safeVersion - The version of the Safe contract. | ||
* @param isL1SafeSingleton - A flag indicating if the contract is a L1 Safe Singleton. | ||
* @param customContractAddress - Optional custom address for the contract. If not provided, the address is derived from the Safe deployments based on the chainId and safeVersion. | ||
* @param customContractAbi - Optional custom ABI for the contract. If not provided, the ABI is derived from the Safe deployments or the defaultAbi is used. | ||
*/ | ||
constructor( | ||
chainId: bigint, | ||
ethersAdapter: EthersAdapter, | ||
defaultAbi: SafeContractAbiType, | ||
safeVersion: SafeVersion, | ||
isL1SafeSingleton = false, | ||
customContractAddress?: string, | ||
customContractAbi?: SafeContractAbiType | ||
) { | ||
super( | ||
chainId, | ||
defaultAbi, | ||
safeVersion, | ||
isL1SafeSingleton, | ||
customContractAddress, | ||
customContractAbi | ||
) | ||
|
||
this.adapter = ethersAdapter | ||
this.contract = new Contract(this.contractAddress, this.contractAbi, this.adapter.getSigner()) | ||
} | ||
} | ||
|
||
export default SafeBaseContractEthers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
...ages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.3.0/SafeContract_V1_3_0_Ethers.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.