diff --git a/packages/protocol-kit/scripts/generateTypechainFiles.ts b/packages/protocol-kit/scripts/generateTypechainFiles.ts index 280287dfd..89c3c9f31 100644 --- a/packages/protocol-kit/scripts/generateTypechainFiles.ts +++ b/packages/protocol-kit/scripts/generateTypechainFiles.ts @@ -16,27 +16,16 @@ const outDirTests = 'typechain/tests/' const safeContractsPath = '../../node_modules/@safe-global/safe-deployments/dist/assets' const safeContracts_V1_4_1 = [ - // `${safeContractsPath}/v1.4.1/safe.json`, // Remove contract 1.4.1 from typechain as it's migrated to Abitype - `${safeContractsPath}/v1.4.1/safe_proxy_factory.json`, `${safeContractsPath}/v1.4.1/compatibility_fallback_handler.json`, `${safeContractsPath}/v1.4.1/create_call.json`, `${safeContractsPath}/v1.4.1/simulate_tx_accessor.json` ].join(' ') const safeContracts_V1_3_0 = [ - // `${safeContractsPath}/v1.3.0/gnosis_safe.json`, // Remove contract 1.3.0 from typechain as it's migrated to Abitype - `${safeContractsPath}/v1.3.0/proxy_factory.json`, `${safeContractsPath}/v1.3.0/compatibility_fallback_handler.json`, `${safeContractsPath}/v1.3.0/create_call.json`, `${safeContractsPath}/v1.3.0/simulate_tx_accessor.json` ].join(' ') -const safeContracts_V1_1_1 = [ - // `${safeContractsPath}/v1.1.1/gnosis_safe.json`, // Remove contract 1.1.1 from typechain as it's migrated to Abitype, - `${safeContractsPath}/v1.1.1/proxy_factory.json` -].join(' ') -const safeContracts_V1_0_0 = [ - `${safeContractsPath}/v1.0.0/gnosis_safe.json`, - `${safeContractsPath}/v1.0.0/proxy_factory.json` -].join(' ') +const safeContracts_V1_0_0 = [`${safeContractsPath}/v1.0.0/gnosis_safe.json`].join(' ') // Won't be included in dist/ folder const safeContractsTestV1_4_1Path = @@ -90,7 +79,7 @@ function moveTypechainFiles(inDir: string, outDir: string): void { }) } -// Contract 1.2.0 is migrated to Abitype already, so it's not included in here +// Contracts v1.1.1 + v1.2.0 are migrated to Abitype already, so they're not included in here function generateTypes(typechainTarget: string) { // Src generateTypechainFiles( @@ -103,11 +92,6 @@ function generateTypes(typechainTarget: string) { `${outDirSrc}${typechainTarget}/v1.3.0`, safeContracts_V1_3_0 ) - generateTypechainFiles( - typechainTarget, - `${outDirSrc}${typechainTarget}/v1.1.1`, - safeContracts_V1_1_1 - ) generateTypechainFiles( typechainTarget, `${outDirSrc}${typechainTarget}/v1.0.0`, @@ -121,10 +105,6 @@ function generateTypes(typechainTarget: string) { `${typeChainDirectorySrcPath}${typechainTarget}/v1.3.0`, `${typeChainDirectoryBuildPath}${typechainTarget}/v1.3.0` ) - moveTypechainFiles( - `${typeChainDirectorySrcPath}${typechainTarget}/v1.1.1`, - `${typeChainDirectoryBuildPath}${typechainTarget}/v1.1.1` - ) moveTypechainFiles( `${typeChainDirectorySrcPath}${typechainTarget}/v1.0.0`, `${typeChainDirectoryBuildPath}${typechainTarget}/v1.0.0` diff --git a/packages/protocol-kit/src/adapters/SafeProxyFactoryBaseContract.ts b/packages/protocol-kit/src/adapters/SafeProxyFactoryBaseContract.ts new file mode 100644 index 000000000..649eca305 --- /dev/null +++ b/packages/protocol-kit/src/adapters/SafeProxyFactoryBaseContract.ts @@ -0,0 +1,58 @@ +import { contractName, getContractDeployment } from '@safe-global/protocol-kit/contracts/config' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * Abstract class SafeProxyFactoryBaseContract serves as a base for creating a Safe Proxy Factory 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 SafeProxyFactoryBaseContractEthers, SafeProxyFactoryBaseContractWeb3, and SafeProxyFactoryBaseContractViem. + * + * @template SafeProxyFactoryContractAbiType - The ABI associated with the Safe Proxy Factory contract. + * + * Example subclasses extending this base class: + * - SafeProxyFactoryBaseContractEthers extends SafeProxyFactoryBaseContract + * - SafeProxyFactoryBaseContractWeb3 extends SafeProxyFactoryBaseContract + * - SafeProxyFactoryBaseContractViem extends SafeProxyFactoryBaseContract + */ +abstract class SafeProxyFactoryBaseContract { + contractAbi: SafeProxyFactoryContractAbiType + contractAddress: string + + readonly contractName: contractName = 'safeProxyFactoryVersion' + 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 SafeProxyFactoryBaseContract instance. + * + * @param chainId - The chain ID of the contract. + * @param defaultAbi - The hardcoded ABI of the Safe Proxy Factory contract. + * @param safeVersion - The version of the Safe contract. + * @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: SafeProxyFactoryContractAbiType, + safeVersion: SafeVersion, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContractAbiType + ) { + const contractDeployment = getContractDeployment(safeVersion, chainId, this.contractName) + + const contractAddress = customContractAddress || contractDeployment?.defaultAddress + + if (!contractAddress) { + throw new Error('Invalid SafeProxyFactory contract address') + } + + this.contractAddress = contractAddress + this.contractAbi = + customContractAbi || + (contractDeployment?.abi as SafeProxyFactoryContractAbiType) || // 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 SafeProxyFactoryBaseContract diff --git a/packages/protocol-kit/src/adapters/ethers/EthersAdapter.ts b/packages/protocol-kit/src/adapters/ethers/EthersAdapter.ts index 47b35114c..f391c43ff 100644 --- a/packages/protocol-kit/src/adapters/ethers/EthersAdapter.ts +++ b/packages/protocol-kit/src/adapters/ethers/EthersAdapter.ts @@ -11,7 +11,6 @@ import { ethers, TransactionResponse, AbstractSigner, Provider } from 'ethers' import CompatibilityFallbackHandlerContractEthers from './contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerEthersContract' import CreateCallEthersContract from './contracts/CreateCall/CreateCallEthersContract' import SafeContractEthers from './contracts/Safe/SafeContractEthers' -import SafeProxyFactoryEthersContract from './contracts/SafeProxyFactory/SafeProxyFactoryEthersContract' import SimulateTxAccessorEthersContract from './contracts/SimulateTxAccessor/SimulateTxAccessorEthersContract' import { getCompatibilityFallbackHandlerContractInstance, @@ -122,8 +121,9 @@ class EthersAdapter implements EthAdapter { async getSafeProxyFactoryContract({ safeVersion, singletonDeployment, - customContractAddress - }: GetContractProps): Promise { + customContractAddress, + customContractAbi + }: GetContractProps) { const chainId = await this.getChainId() const contractAddress = customContractAddress ?? singletonDeployment?.networkAddresses[chainId.toString()] @@ -131,7 +131,13 @@ class EthersAdapter implements EthAdapter { throw new Error('Invalid SafeProxyFactory contract address') } const signerOrProvider = this.#signer || this.#provider - return getSafeProxyFactoryContractInstance(safeVersion, contractAddress, signerOrProvider) + return getSafeProxyFactoryContractInstance( + safeVersion, + contractAddress, + signerOrProvider, + this, + customContractAbi + ) } async getMultiSendContract({ diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers.ts new file mode 100644 index 000000000..33bc1bb8e --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers.ts @@ -0,0 +1,62 @@ +import { Contract, ContractRunner, InterfaceAbi } from 'ethers' + +import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' +import SafeProxyFactoryBaseContract from '@safe-global/protocol-kit/adapters/SafeProxyFactoryBaseContract' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * Abstract class SafeProxyFactoryBaseContractEthers extends SafeProxyFactoryBaseContract 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 Proxy Factory contract version. + * + * Subclasses of SafeProxyFactoryBaseContractEthers are expected to represent specific versions of the contract. + * + * @template SafeProxyFactoryContractAbiType - The ABI type specific to the version of the Safe Proxy Factory contract, extending InterfaceAbi from Ethers. + * @extends SafeProxyFactoryBaseContract - Extends the generic SafeProxyFactoryBaseContract with Ethers-specific implementation. + * + * Example subclasses: + * - SafeProxyFactoryContract_v1_4_1_Ethers extends SafeProxyFactoryBaseContractEthers + * - SafeProxyFactoryContract_v1_3_0_Ethers extends SafeProxyFactoryBaseContractEthers + * - SafeProxyFactoryContract_v1_2_0_Ethers extends SafeProxyFactoryBaseContractEthers + * - SafeProxyFactoryContract_v1_1_1_Ethers extends SafeProxyFactoryBaseContractEthers + * - SafeProxyFactoryContract_v1_0_0_Ethers extends SafeProxyFactoryBaseContractEthers + */ +abstract class SafeProxyFactoryBaseContractEthers< + SafeProxyFactoryContractAbiType extends InterfaceAbi +> extends SafeProxyFactoryBaseContract { + contract: Contract + adapter: EthersAdapter + + /** + * @constructor + * Constructs an instance of SafeProxyFactoryBaseContractEthers. + * + * @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 contract. + * @param safeVersion - The version of the Safe contract. + * @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: SafeProxyFactoryContractAbiType, + safeVersion: SafeVersion, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContractAbiType, + runner?: ContractRunner | null + ) { + super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + + this.adapter = ethersAdapter + this.contract = new Contract( + this.contractAddress, + this.contractAbi, + runner || this.adapter.getSigner() + ) + } +} + +export default SafeProxyFactoryBaseContractEthers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryEthersContract.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryEthersContract.ts deleted file mode 100644 index d4829c1e9..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryEthersContract.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { EventLog } from 'ethers' -import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers/types' -import { Proxy_factory as SafeProxyFactory_V1_0_0 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.0.0/Proxy_factory' -import { Proxy_factory as SafeProxyFactory_V1_1_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.1.1/Proxy_factory' -import { Proxy_factory as SafeProxyFactory_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/Proxy_factory' -import { Safe_proxy_factory as SafeProxyFactory_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/Safe_proxy_factory' -import { SafeProxyFactoryContract } from '@safe-global/safe-core-sdk-types' - -export interface CreateProxyProps { - safeSingletonAddress: string - initializer: string - saltNonce: string - options?: EthersTransactionOptions - callback?: (txHash: string) => void -} - -class SafeProxyFactoryEthersContract implements SafeProxyFactoryContract { - constructor( - public contract: - | SafeProxyFactory_V1_4_1 - | SafeProxyFactory_V1_3_0 - | SafeProxyFactory_V1_1_1 - | SafeProxyFactory_V1_0_0 - ) {} - - getAddress(): Promise { - return this.contract.getAddress() - } - - async proxyCreationCode(): Promise { - return this.contract.proxyCreationCode() - } - - async createProxy({ - safeSingletonAddress, - initializer, - saltNonce, - options, - callback - }: CreateProxyProps): Promise { - if (BigInt(saltNonce) < 0) throw new Error('saltNonce must be greater than or equal to 0') - - if (options && !options.gasLimit) { - options.gasLimit = await this.estimateGas( - 'createProxyWithNonce', - [safeSingletonAddress, initializer, saltNonce], - { - ...options - } - ) - } - const proxyAddress = this.contract - .createProxyWithNonce(safeSingletonAddress, initializer, saltNonce, { ...options }) - .then(async (txResponse) => { - if (callback) { - callback(txResponse.hash) - } - const txReceipt = await txResponse.wait() - const events = txReceipt?.logs as EventLog[] - const proxyCreationEvent = events.find((event) => event?.eventName === 'ProxyCreation') - if (!proxyCreationEvent || !proxyCreationEvent.args) { - throw new Error('SafeProxy was not deployed correctly') - } - const proxyAddress: string = proxyCreationEvent.args[0] - return proxyAddress - }) - return proxyAddress - } - - encode(methodName: string, params: any[]): string { - return (this.contract as any).interface.encodeFunctionData(methodName, params) - } - - async estimateGas( - methodName: string, - params: any[], - options: EthersTransactionOptions - ): Promise { - const method = this.contract.getFunction(methodName) - - return (await method.estimateGas(...params, options)).toString() - } -} - -export default SafeProxyFactoryEthersContract diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_V1_0_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_V1_0_0_Ethers.ts deleted file mode 100644 index eeb302cce..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_V1_0_0_Ethers.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Proxy_factory as ProxyFactory } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.0.0/Proxy_factory' -import SafeProxyFactoryEthersContract from '../SafeProxyFactoryEthersContract' - -class SafeProxyFactoryContract_V1_0_0_Ethers extends SafeProxyFactoryEthersContract { - constructor(public contract: ProxyFactory) { - super(contract) - } -} - -export default SafeProxyFactoryContract_V1_0_0_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0_Ethers.ts new file mode 100644 index 000000000..5cbcefc1c --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0_Ethers.ts @@ -0,0 +1,162 @@ +import { ContractRunner, EventLog } from 'ethers' +import SafeProxyFactoryBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers' +import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' +import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers/types' +import safeProxyFactory_1_0_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.0.0/proxy_factory' +import { + EncodeSafeProxyFactoryFunction, + EstimateGasSafeProxyFactoryFunction +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import SafeProxyFactoryContract_v1_0_0_Contract, { + SafeProxyFactoryContract_v1_0_0_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * SafeProxyFactoryContract_v1_0_0_Ethers is the implementation specific to the Safe Proxy Factory contract version 1.0.0. + * + * This class specializes in handling interactions with the Safe Proxy Factory contract version 1.0.0 using Ethers.js v6. + * + * @extends SafeProxyFactoryBaseContractEthers - Inherits from SafeProxyFactoryBaseContractEthers with ABI specific to Safe Proxy Factory contract version 1.0.0. + * @implements SafeProxyFactoryContract_v1_0_0_Contract - Implements the interface specific to Safe Proxy Factory contract version 1.0.0. + */ +class SafeProxyFactoryContract_v1_0_0_Ethers + extends SafeProxyFactoryBaseContractEthers + implements SafeProxyFactoryContract_v1_0_0_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SafeProxyFactoryContract_v1_0_0_Ethers + * + * @param chainId - The chain ID where the contract resides. + * @param ethersAdapter - An instance of EthersAdapter. + * @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 default ABI for version 1.0.0 is used. + */ + constructor( + chainId: bigint, + ethersAdapter: EthersAdapter, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContract_v1_0_0_Abi, + runner?: ContractRunner | null + ) { + const safeVersion = '1.0.0' + const defaultAbi = safeProxyFactory_1_0_0_ContractArtifacts.abi + + super( + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi, + runner + ) + + this.safeVersion = safeVersion + } + + encode: EncodeSafeProxyFactoryFunction = ( + functionToEncode, + args + ) => { + return this.contract.interface.encodeFunctionData(functionToEncode, args) + } + + estimateGas: EstimateGasSafeProxyFactoryFunction< + SafeProxyFactoryContract_v1_0_0_Abi, + EthersTransactionOptions + > = (functionToEstimate, args, options = {}) => { + const contractMethodToStimate = this.contract.getFunction(functionToEstimate) + + return contractMethodToStimate.estimateGas(...args, options) + } + + getAddress(): Promise { + return this.contract.getAddress() + } + + async proxyCreationCode(): Promise<[string]> { + return [await this.contract.proxyCreationCode()] + } + + async proxyRuntimeCode(): Promise<[string]> { + return [await this.contract.proxyRuntimeCode()] + } + + async createProxy(args: readonly [masterCopy: string, data: string]): Promise<[string]> { + return [await this.contract.createProxy(...args)] + } + + async createProxyWithNonce( + args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.createProxyWithNonce(...args)] + } + + async createProxyWithOptions({ + safeSingletonAddress, + initializer, + saltNonce, + options, + callback + }: { + safeSingletonAddress: string + initializer: string + saltNonce: string + options?: EthersTransactionOptions + callback?: (txHash: string) => void + }): Promise { + const saltNonceBigInt = BigInt(saltNonce) + + if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') + + if (options && !options.gasLimit) { + options.gasLimit = ( + await this.estimateGas( + 'createProxyWithNonce', + [safeSingletonAddress, initializer, saltNonceBigInt], + { ...options } + ) + ).toString() + } + + const proxyAddress = this.contract + .createProxyWithNonce(safeSingletonAddress, initializer, saltNonce, { ...options }) + .then(async (txResponse) => { + if (callback) { + callback(txResponse.hash) + } + const txReceipt = await txResponse.wait() + const events = txReceipt?.logs as EventLog[] + const proxyCreationEvent = events.find((event) => event?.eventName === 'ProxyCreation') + if (!proxyCreationEvent || !proxyCreationEvent.args) { + throw new Error('SafeProxy was not deployed correctly') + } + const proxyAddress: string = proxyCreationEvent.args[0] + return proxyAddress + }) + return proxyAddress + } + + // TODO: Remove this mapper after remove Typechain + mapToTypechainContract(): any { + return { + contract: this.contract, + + encode: this.encode.bind(this), + + estimateGas: async (...args: Parameters) => + (await this.estimateGas(...args)).toString(), + + createProxy: this.createProxyWithOptions.bind(this), + + getAddress: this.getAddress.bind(this), + + proxyCreationCode: async () => (await this.proxyCreationCode())[0] + } + } +} + +export default SafeProxyFactoryContract_v1_0_0_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_V1_1_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_V1_1_1_Ethers.ts deleted file mode 100644 index fcac49d5f..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_V1_1_1_Ethers.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Proxy_factory as ProxyFactory } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.1.1/Proxy_factory' -import SafeProxyFactoryEthersContract from '../SafeProxyFactoryEthersContract' - -class SafeProxyFactoryContract_V1_1_1_Ethers extends SafeProxyFactoryEthersContract { - constructor(public contract: ProxyFactory) { - super(contract) - } -} - -export default SafeProxyFactoryContract_V1_1_1_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1_Ethers.ts new file mode 100644 index 000000000..fc5c70e02 --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1_Ethers.ts @@ -0,0 +1,174 @@ +import { ContractRunner, EventLog } from 'ethers' +import SafeProxyFactoryBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers' +import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' +import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers/types' +import safeProxyFactory_1_1_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.1.1/proxy_factory' +import { + EncodeSafeProxyFactoryFunction, + EstimateGasSafeProxyFactoryFunction +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import SafeProxyFactoryContract_v1_1_1_Contract, { + SafeProxyFactoryContract_v1_1_1_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * SafeProxyFactoryContract_v1_1_1_Ethers is the implementation specific to the Safe Proxy Factory contract version 1.1.1. + * + * This class specializes in handling interactions with the Safe Proxy Factory contract version 1.1.1 using Ethers.js v6. + * + * @extends SafeProxyFactoryBaseContractEthers - Inherits from SafeProxyFactoryBaseContractEthers with ABI specific to Safe Proxy Factory contract version 1.1.1. + * @implements SafeProxyFactoryContract_v1_1_1_Contract - Implements the interface specific to Safe Proxy Factory contract version 1.1.1. + */ +class SafeProxyFactoryContract_v1_1_1_Ethers + extends SafeProxyFactoryBaseContractEthers + implements SafeProxyFactoryContract_v1_1_1_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SafeProxyFactoryContract_v1_1_1_Ethers + * + * @param chainId - The chain ID where the contract resides. + * @param ethersAdapter - An instance of EthersAdapter. + * @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 default ABI for version 1.1.1 is used. + */ + constructor( + chainId: bigint, + ethersAdapter: EthersAdapter, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContract_v1_1_1_Abi, + runner?: ContractRunner | null + ) { + const safeVersion = '1.1.1' + const defaultAbi = safeProxyFactory_1_1_1_ContractArtifacts.abi + + super( + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi, + runner + ) + + this.safeVersion = safeVersion + } + + encode: EncodeSafeProxyFactoryFunction = ( + functionToEncode, + args + ) => { + return this.contract.interface.encodeFunctionData(functionToEncode, args) + } + + estimateGas: EstimateGasSafeProxyFactoryFunction< + SafeProxyFactoryContract_v1_1_1_Abi, + EthersTransactionOptions + > = (functionToEstimate, args, options = {}) => { + const contractMethodToStimate = this.contract.getFunction(functionToEstimate) + + return contractMethodToStimate.estimateGas(...args, options) + } + + getAddress(): Promise { + return this.contract.getAddress() + } + + async proxyCreationCode(): Promise<[string]> { + return [await this.contract.proxyCreationCode()] + } + + async proxyRuntimeCode(): Promise<[string]> { + return [await this.contract.proxyRuntimeCode()] + } + + async calculateCreateProxyWithNonceAddress( + args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.calculateCreateProxyWithNonceAddress(...args)] + } + + async createProxy(args: readonly [masterCopy: string, data: string]): Promise<[string]> { + return [await this.contract.createProxy(...args)] + } + + async createProxyWithCallback( + args: readonly [masterCopy: string, initializer: string, saltNonce: bigint, callback: string] + ): Promise<[string]> { + return [await this.contract.createProxyWithCallback(...args)] + } + + async createProxyWithNonce( + args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.createProxyWithNonce(...args)] + } + + async createProxyWithOptions({ + safeSingletonAddress, + initializer, + saltNonce, + options, + callback + }: { + safeSingletonAddress: string + initializer: string + saltNonce: string + options?: EthersTransactionOptions + callback?: (txHash: string) => void + }): Promise { + const saltNonceBigInt = BigInt(saltNonce) + + if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') + + if (options && !options.gasLimit) { + options.gasLimit = ( + await this.estimateGas( + 'createProxyWithNonce', + [safeSingletonAddress, initializer, saltNonceBigInt], + { ...options } + ) + ).toString() + } + + const proxyAddress = this.contract + .createProxyWithNonce(safeSingletonAddress, initializer, saltNonce, { ...options }) + .then(async (txResponse) => { + if (callback) { + callback(txResponse.hash) + } + const txReceipt = await txResponse.wait() + const events = txReceipt?.logs as EventLog[] + const proxyCreationEvent = events.find((event) => event?.eventName === 'ProxyCreation') + if (!proxyCreationEvent || !proxyCreationEvent.args) { + throw new Error('SafeProxy was not deployed correctly') + } + const proxyAddress: string = proxyCreationEvent.args[0] + return proxyAddress + }) + return proxyAddress + } + + // TODO: Remove this mapper after remove Typechain + mapToTypechainContract(): any { + return { + contract: this.contract, + + encode: this.encode.bind(this), + + estimateGas: async (...args: Parameters) => + (await this.estimateGas(...args)).toString(), + + createProxy: this.createProxyWithOptions.bind(this), + + getAddress: this.getAddress.bind(this), + + proxyCreationCode: async () => (await this.proxyCreationCode())[0] + } + } +} + +export default SafeProxyFactoryContract_v1_1_1_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_V1_3_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_V1_3_0_Ethers.ts deleted file mode 100644 index 12c731c99..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_V1_3_0_Ethers.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Proxy_factory as ProxyFactory } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/Proxy_factory' -import SafeProxyFactoryEthersContract from '../SafeProxyFactoryEthersContract' - -class SafeProxyFactoryContract_V1_3_0_Ethers extends SafeProxyFactoryEthersContract { - constructor(public contract: ProxyFactory) { - super(contract) - } -} - -export default SafeProxyFactoryContract_V1_3_0_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0_Ethers.ts new file mode 100644 index 000000000..b2d516176 --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0_Ethers.ts @@ -0,0 +1,174 @@ +import { ContractRunner, EventLog } from 'ethers' +import SafeProxyFactoryBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers' +import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' +import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers/types' +import safeProxyFactory_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.3.0/proxy_factory' +import { + EncodeSafeProxyFactoryFunction, + EstimateGasSafeProxyFactoryFunction +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import SafeProxyFactoryContract_v1_3_0_Contract, { + SafeProxyFactoryContract_v1_3_0_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * SafeProxyFactoryContract_v1_3_0_Ethers is the implementation specific to the Safe Proxy Factory contract version 1.3.0. + * + * This class specializes in handling interactions with the Safe Proxy Factory contract version 1.3.0 using Ethers.js v6. + * + * @extends SafeProxyFactoryBaseContractEthers - Inherits from SafeProxyFactoryBaseContractEthers with ABI specific to Safe Proxy Factory contract version 1.3.0. + * @implements SafeProxyFactoryContract_v1_3_0_Contract - Implements the interface specific to Safe Proxy Factory contract version 1.3.0. + */ +class SafeProxyFactoryContract_v1_3_0_Ethers + extends SafeProxyFactoryBaseContractEthers + implements SafeProxyFactoryContract_v1_3_0_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SafeProxyFactoryContract_v1_3_0_Ethers + * + * @param chainId - The chain ID where the contract resides. + * @param ethersAdapter - An instance of EthersAdapter. + * @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 default ABI for version 1.3.0 is used. + */ + constructor( + chainId: bigint, + ethersAdapter: EthersAdapter, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContract_v1_3_0_Abi, + runner?: ContractRunner | null + ) { + const safeVersion = '1.3.0' + const defaultAbi = safeProxyFactory_1_3_0_ContractArtifacts.abi + + super( + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi, + runner + ) + + this.safeVersion = safeVersion + } + + encode: EncodeSafeProxyFactoryFunction = ( + functionToEncode, + args + ) => { + return this.contract.interface.encodeFunctionData(functionToEncode, args) + } + + estimateGas: EstimateGasSafeProxyFactoryFunction< + SafeProxyFactoryContract_v1_3_0_Abi, + EthersTransactionOptions + > = (functionToEstimate, args, options = {}) => { + const contractMethodToStimate = this.contract.getFunction(functionToEstimate) + + return contractMethodToStimate.estimateGas(...args, options) + } + + getAddress(): Promise { + return this.contract.getAddress() + } + + async proxyCreationCode(): Promise<[string]> { + return [await this.contract.proxyCreationCode()] + } + + async proxyRuntimeCode(): Promise<[string]> { + return [await this.contract.proxyRuntimeCode()] + } + + async calculateCreateProxyWithNonceAddress( + args: readonly [singleton: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.calculateCreateProxyWithNonceAddress(...args)] + } + + async createProxy(args: readonly [singleton: string, data: string]): Promise<[string]> { + return [await this.contract.createProxy(...args)] + } + + async createProxyWithCallback( + args: readonly [singleton: string, initializer: string, saltNonce: bigint, callback: string] + ): Promise<[string]> { + return [await this.contract.createProxyWithCallback(...args)] + } + + async createProxyWithNonce( + args: readonly [singleton: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.createProxyWithNonce(...args)] + } + + async createProxyWithOptions({ + safeSingletonAddress, + initializer, + saltNonce, + options, + callback + }: { + safeSingletonAddress: string + initializer: string + saltNonce: string + options?: EthersTransactionOptions + callback?: (txHash: string) => void + }): Promise { + const saltNonceBigInt = BigInt(saltNonce) + + if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') + + if (options && !options.gasLimit) { + options.gasLimit = ( + await this.estimateGas( + 'createProxyWithNonce', + [safeSingletonAddress, initializer, saltNonceBigInt], + { ...options } + ) + ).toString() + } + + const proxyAddress = this.contract + .createProxyWithNonce(safeSingletonAddress, initializer, saltNonce, { ...options }) + .then(async (txResponse) => { + if (callback) { + callback(txResponse.hash) + } + const txReceipt = await txResponse.wait() + const events = txReceipt?.logs as EventLog[] + const proxyCreationEvent = events.find((event) => event?.eventName === 'ProxyCreation') + if (!proxyCreationEvent || !proxyCreationEvent.args) { + throw new Error('SafeProxy was not deployed correctly') + } + const proxyAddress: string = proxyCreationEvent.args[0] + return proxyAddress + }) + return proxyAddress + } + + // TODO: Remove this mapper after remove Typechain + mapToTypechainContract(): any { + return { + contract: this.contract, + + encode: this.encode.bind(this), + + estimateGas: async (...args: Parameters) => + (await this.estimateGas(...args)).toString(), + + createProxy: this.createProxyWithOptions.bind(this), + + getAddress: this.getAddress.bind(this), + + proxyCreationCode: async () => (await this.proxyCreationCode())[0] + } + } +} + +export default SafeProxyFactoryContract_v1_3_0_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_V1_4_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_V1_4_1_Ethers.ts deleted file mode 100644 index c6d960eaa..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_V1_4_1_Ethers.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Safe_proxy_factory as SafeProxyFactory } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/Safe_proxy_factory' -import SafeProxyFactoryEthersContract from '../SafeProxyFactoryEthersContract' - -class SafeProxyFactoryContract_V1_4_1_Ethers extends SafeProxyFactoryEthersContract { - constructor(public contract: SafeProxyFactory) { - super(contract) - } -} - -export default SafeProxyFactoryContract_V1_4_1_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Ethers.ts new file mode 100644 index 000000000..bf9ff98fe --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Ethers.ts @@ -0,0 +1,170 @@ +import { ContractRunner, EventLog } from 'ethers' +import SafeProxyFactoryBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers' +import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' +import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers/types' +import safeProxyFactory_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.4.1/safe_proxy_factory' +import { + EncodeSafeProxyFactoryFunction, + EstimateGasSafeProxyFactoryFunction +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import SafeProxyFactoryContract_v1_4_1_Contract, { + SafeProxyFactoryContract_v1_4_1_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * SafeProxyFactoryContract_v1_4_1_Ethers is the implementation specific to the Safe Proxy Factory contract version 1.4.1. + * + * This class specializes in handling interactions with the Safe Proxy Factory contract version 1.4.1 using Ethers.js v6. + * + * @extends SafeProxyFactoryBaseContractEthers - Inherits from SafeProxyFactoryBaseContractEthers with ABI specific to Safe Proxy Factory contract version 1.4.1. + * @implements SafeProxyFactoryContract_v1_4_1_Contract - Implements the interface specific to Safe Proxy Factory contract version 1.4.1. + */ +class SafeProxyFactoryContract_v1_4_1_Ethers + extends SafeProxyFactoryBaseContractEthers + implements SafeProxyFactoryContract_v1_4_1_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SafeProxyFactoryContract_v1_4_1_Ethers + * + * @param chainId - The chain ID where the contract resides. + * @param ethersAdapter - An instance of EthersAdapter. + * @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 default ABI for version 1.4.1 is used. + */ + constructor( + chainId: bigint, + ethersAdapter: EthersAdapter, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContract_v1_4_1_Abi, + runner?: ContractRunner | null + ) { + const safeVersion = '1.4.1' + const defaultAbi = safeProxyFactory_1_4_1_ContractArtifacts.abi + + super( + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi, + runner + ) + + this.safeVersion = safeVersion + } + + encode: EncodeSafeProxyFactoryFunction = ( + functionToEncode, + args + ) => { + return this.contract.interface.encodeFunctionData(functionToEncode, args) + } + + estimateGas: EstimateGasSafeProxyFactoryFunction< + SafeProxyFactoryContract_v1_4_1_Abi, + EthersTransactionOptions + > = (functionToEstimate, args, options = {}) => { + const contractMethodToStimate = this.contract.getFunction(functionToEstimate) + + return contractMethodToStimate.estimateGas(...args, options) + } + + getAddress(): Promise { + return this.contract.getAddress() + } + + async getChainId(): Promise<[bigint]> { + return [await this.contract.getChainId()] + } + + async proxyCreationCode(): Promise<[string]> { + return [await this.contract.proxyCreationCode()] + } + + async createChainSpecificProxyWithNonce( + args: readonly [singleton: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.createChainSpecificProxyWithNonce(...args)] + } + + async createProxyWithCallback( + args: readonly [singleton: string, initializer: string, saltNonce: bigint, callback: string] + ): Promise<[string]> { + return [await this.contract.createProxyWithCallback(...args)] + } + + async createProxyWithNonce( + args: readonly [singleton: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.createProxyWithNonce(...args)] + } + + async createProxy({ + safeSingletonAddress, + initializer, + saltNonce, + options, + callback + }: { + safeSingletonAddress: string + initializer: string + saltNonce: string + options?: EthersTransactionOptions + callback?: (txHash: string) => void + }): Promise { + const saltNonceBigInt = BigInt(saltNonce) + + if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') + + if (options && !options.gasLimit) { + options.gasLimit = ( + await this.estimateGas( + 'createProxyWithNonce', + [safeSingletonAddress, initializer, saltNonceBigInt], + { ...options } + ) + ).toString() + } + + const proxyAddress = this.contract + .createProxyWithNonce(safeSingletonAddress, initializer, saltNonce, { ...options }) + .then(async (txResponse) => { + if (callback) { + callback(txResponse.hash) + } + const txReceipt = await txResponse.wait() + const events = txReceipt?.logs as EventLog[] + const proxyCreationEvent = events.find((event) => event?.eventName === 'ProxyCreation') + if (!proxyCreationEvent || !proxyCreationEvent.args) { + throw new Error('SafeProxy was not deployed correctly') + } + const proxyAddress: string = proxyCreationEvent.args[0] + return proxyAddress + }) + return proxyAddress + } + + // TODO: Remove this mapper after remove Typechain + mapToTypechainContract(): any { + return { + contract: this.contract, + + encode: this.encode.bind(this), + + estimateGas: async (...args: Parameters) => + (await this.estimateGas(...args)).toString(), + + createProxy: this.createProxy.bind(this), + + getAddress: this.getAddress.bind(this), + + proxyCreationCode: async () => (await this.proxyCreationCode())[0] + } + } +} + +export default SafeProxyFactoryContract_v1_4_1_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts index 26f0896ca..0e3a1867e 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts @@ -1,15 +1,11 @@ import { AbstractSigner, Provider } from 'ethers' import { AbiItem } from 'web3-utils' import { Gnosis_safe__factory as SafeSingleton_V1_0_0 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.0.0/factories/Gnosis_safe__factory' -import { Proxy_factory__factory as SafeProxyFactory_V1_0_0 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.0.0/factories/Proxy_factory__factory' -import { Proxy_factory__factory as SafeProxyFactory_V1_1_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.1.1/factories/Proxy_factory__factory' import { Compatibility_fallback_handler__factory as CompatibilityFallbackHandler_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/factories/Compatibility_fallback_handler__factory' import { Create_call__factory as CreateCall_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/factories/Create_call__factory' -import { Proxy_factory__factory as SafeProxyFactory_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/factories/Proxy_factory__factory' import { Simulate_tx_accessor__factory as SimulateTxAccessor_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/factories/Simulate_tx_accessor__factory' import { Compatibility_fallback_handler__factory as CompatibilityFallbackHandler_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/factories/Compatibility_fallback_handler__factory' import { Create_call__factory as CreateCall_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/factories/Create_call__factory' -import { Safe_proxy_factory__factory as SafeProxyFactory_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/factories/Safe_proxy_factory__factory' import { Simulate_tx_accessor__factory as SimulateTxAccessor_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/factories/Simulate_tx_accessor__factory' import { SafeVersion, SignMessageLibContract } from '@safe-global/safe-core-sdk-types' import CompatibilityFallbackHandler_V1_3_0_Ethers from './CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandler_V1_3_0_Ethers' @@ -22,10 +18,6 @@ import MultiSendContract_V1_4_1_Ethers from './MultiSend/v1.4.1/MultiSendContrac import MultiSendCallOnlyContract_V1_3_0_Ethers from './MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Ethers' import MultiSendCallOnlyContract_V1_4_1_Ethers from './MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Ethers' import SafeContract_V1_0_0_Ethers from './Safe/v1.0.0/SafeContract_V1_0_0_Ethers' -import SafeProxyFactoryContract_V1_0_0_Ethers from './SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_V1_0_0_Ethers' -import SafeProxyFactoryContract_V1_1_1_Ethers from './SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_V1_1_1_Ethers' -import SafeProxyFactoryContract_V1_3_0_Ethers from './SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_V1_3_0_Ethers' -import SafeProxyFactoryContract_V1_4_1_Ethers from './SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_V1_4_1_Ethers' import SignMessageLibContract_V1_3_0_Ethers from './SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Ethers' import SignMessageLibContract_V1_4_1_Ethers from './SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Ethers' import SimulateTxAccessorContract_V1_3_0_Ethers from './SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_V1_3_0_Ethers' @@ -33,6 +25,10 @@ import SimulateTxAccessorContract_V1_4_1_Ethers from './SimulateTxAccessor/v1.4. import SafeContract_v1_1_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/Safe/v1.1.1/SafeContract_v1_1_1_Ethers' import SafeContract_v1_2_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/Safe/v1.2.0/SafeContract_v1_2_0_Ethers' import SafeContract_v1_3_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Ethers' +import SafeProxyFactoryContract_v1_0_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0_Ethers' +import SafeProxyFactoryContract_v1_1_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1_Ethers' +import SafeProxyFactoryContract_v1_3_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0_Ethers' +import SafeProxyFactoryContract_v1_4_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Ethers' import SafeContract_v1_4_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Ethers' import EthersAdapter from '../EthersAdapter' import { SafeContract_v1_1_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.1.1/SafeContract_v1_1_1' @@ -46,6 +42,10 @@ import { MultiSendCallOnlyContract_v1_3_0_Abi } from '@safe-global/protocol-kit/ import { MultiSendCallOnlyContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.4.1/MultiSendCallOnlyContract_v1_4_1' import { SignMessageLibContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/v1.4.1/SignMessageLibContract_v1_4_1' import { SignMessageLibContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/v1.3.0/SignMessageLibContract_v1_3_0' +import { SafeProxyFactoryContract_v1_0_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0' +import { SafeProxyFactoryContract_v1_1_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1' +import { SafeProxyFactoryContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0' +import { SafeProxyFactoryContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1' export async function getSafeContractInstance( safeVersion: SafeVersion, @@ -205,30 +205,58 @@ export async function getMultiSendCallOnlyContractInstance( } } -export function getSafeProxyFactoryContractInstance( +export async function getSafeProxyFactoryContractInstance( safeVersion: SafeVersion, contractAddress: string, - signerOrProvider: AbstractSigner | Provider -): - | SafeProxyFactoryContract_V1_4_1_Ethers - | SafeProxyFactoryContract_V1_3_0_Ethers - | SafeProxyFactoryContract_V1_1_1_Ethers - | SafeProxyFactoryContract_V1_0_0_Ethers { + signerOrProvider: AbstractSigner | Provider, + ethersAdapter: EthersAdapter, + customContractAbi?: AbiItem | AbiItem[] | undefined +) { + const chainId = await ethersAdapter.getChainId() let safeProxyFactoryContract switch (safeVersion) { case '1.4.1': - safeProxyFactoryContract = SafeProxyFactory_V1_4_1.connect(contractAddress, signerOrProvider) - return new SafeProxyFactoryContract_V1_4_1_Ethers(safeProxyFactoryContract) + safeProxyFactoryContract = new SafeProxyFactoryContract_v1_4_1_Ethers( + chainId, + ethersAdapter, + contractAddress, + // TODO: Remove this unknown after remove Typechain + customContractAbi as unknown as SafeProxyFactoryContract_v1_4_1_Abi, + signerOrProvider + ) + return safeProxyFactoryContract.mapToTypechainContract() // remove this mapper after remove typechain + case '1.3.0': - safeProxyFactoryContract = SafeProxyFactory_V1_3_0.connect(contractAddress, signerOrProvider) - return new SafeProxyFactoryContract_V1_3_0_Ethers(safeProxyFactoryContract) + safeProxyFactoryContract = new SafeProxyFactoryContract_v1_3_0_Ethers( + chainId, + ethersAdapter, + contractAddress, + // TODO: Remove this unknown after remove Typechain + customContractAbi as unknown as SafeProxyFactoryContract_v1_3_0_Abi, + signerOrProvider + ) + return safeProxyFactoryContract.mapToTypechainContract() // remove this mapper after remove typechain case '1.2.0': case '1.1.1': - safeProxyFactoryContract = SafeProxyFactory_V1_1_1.connect(contractAddress, signerOrProvider) - return new SafeProxyFactoryContract_V1_1_1_Ethers(safeProxyFactoryContract) + safeProxyFactoryContract = new SafeProxyFactoryContract_v1_1_1_Ethers( + chainId, + ethersAdapter, + contractAddress, + // TODO: Remove this unknown after remove Typechain + customContractAbi as unknown as SafeProxyFactoryContract_v1_1_1_Abi, + signerOrProvider + ) + return safeProxyFactoryContract.mapToTypechainContract() // remove this mapper after remove typechain case '1.0.0': - safeProxyFactoryContract = SafeProxyFactory_V1_0_0.connect(contractAddress, signerOrProvider) - return new SafeProxyFactoryContract_V1_0_0_Ethers(safeProxyFactoryContract) + safeProxyFactoryContract = new SafeProxyFactoryContract_v1_0_0_Ethers( + chainId, + ethersAdapter, + contractAddress, + // TODO: Remove this unknown after remove Typechain + customContractAbi as unknown as SafeProxyFactoryContract_v1_0_0_Abi, + signerOrProvider + ) + return safeProxyFactoryContract.mapToTypechainContract() // remove this mapper after remove typechain default: throw new Error('Invalid Safe version') } diff --git a/packages/protocol-kit/src/adapters/ethers/index.ts b/packages/protocol-kit/src/adapters/ethers/index.ts index a5c4c2542..fa5ce35e2 100644 --- a/packages/protocol-kit/src/adapters/ethers/index.ts +++ b/packages/protocol-kit/src/adapters/ethers/index.ts @@ -3,15 +3,12 @@ import CreateCallEthersContract from './contracts/CreateCall/CreateCallEthersCon import MultiSendBaseContractEthers from './contracts/MultiSend/MultiSendBaseContractEthers' import MultiSendCallOnlyBaseContractEthers from './contracts/MultiSend/MultiSendCallOnlyBaseContractEthers' import SafeContractEthers from './contracts/Safe/SafeContractEthers' -import SafeProxyFactoryEthersContract, { - CreateProxyProps -} from './contracts/SafeProxyFactory/SafeProxyFactoryEthersContract' +import SafeProxyFactoryBaseContractEthers from './contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers' import SignMessageLibBaseContractEthers from './contracts/SignMessageLib/SignMessageLibBaseContractEthers' import { EthersTransactionOptions, EthersTransactionResult } from './types' export { CreateCallEthersContract, - CreateProxyProps, EthersAdapter, EthersAdapterConfig, EthersTransactionOptions, @@ -19,6 +16,6 @@ export { MultiSendCallOnlyBaseContractEthers, MultiSendBaseContractEthers, SafeContractEthers, - SafeProxyFactoryEthersContract, + SafeProxyFactoryBaseContractEthers, SignMessageLibBaseContractEthers } diff --git a/packages/protocol-kit/src/adapters/web3/Web3Adapter.ts b/packages/protocol-kit/src/adapters/web3/Web3Adapter.ts index 793209ce2..701a20232 100644 --- a/packages/protocol-kit/src/adapters/web3/Web3Adapter.ts +++ b/packages/protocol-kit/src/adapters/web3/Web3Adapter.ts @@ -18,7 +18,6 @@ import type { JsonRPCResponse, Provider } from 'web3/providers' import CompatibilityFallbackHandlerWeb3Contract from './contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerWeb3Contract' import CreateCallWeb3Contract from './contracts/CreateCall/CreateCallWeb3Contract' import SafeContractWeb3 from './contracts/Safe/SafeContractWeb3' -import SafeProxyFactoryWeb3Contract from './contracts/SafeProxyFactory/SafeProxyFactoryWeb3Contract' import SimulateTxAccessorWeb3Contract from './contracts/SimulateTxAccessor/SimulateTxAccessorWeb3Contract' import { getCompatibilityFallbackHandlerContractInstance, @@ -118,18 +117,19 @@ class Web3Adapter implements EthAdapter { singletonDeployment, customContractAddress, customContractAbi - }: GetContractProps): Promise { + }: GetContractProps) { const chainId = await this.getChainId() const contractAddress = customContractAddress ?? singletonDeployment?.networkAddresses[chainId.toString()] if (!contractAddress) { throw new Error('Invalid SafeProxyFactory contract address') } - const proxyFactoryContract = this.getContract( + return getSafeProxyFactoryContractInstance( + safeVersion, contractAddress, - customContractAbi ?? (singletonDeployment?.abi as AbiItem[]) + this, + customContractAbi ) - return getSafeProxyFactoryContractInstance(safeVersion, proxyFactoryContract) } async getMultiSendContract({ diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3.ts new file mode 100644 index 000000000..25ec95daf --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3.ts @@ -0,0 +1,58 @@ +import Contract from 'web3-eth-contract' +import { AbiItem } from 'web3-utils' + +import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' +import SafeProxyFactoryBaseContract from '@safe-global/protocol-kit/adapters/SafeProxyFactoryBaseContract' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * Abstract class SafeProxyFactoryBaseContractWeb3 extends SafeProxyFactoryBaseContract to specifically integrate with the Web3.js library. + * It is designed to be instantiated for different versions of the Safe contract. + * + * This abstract class sets up the Web3.js Contract object that interacts with a Safe Proxy Factory contract version. + * + * Subclasses of SafeProxyFactoryBaseContractWeb3 are expected to represent specific versions of the contract. + * + * @template SafeProxyFactoryContractAbiType - The ABI type specific to the version of the Safe Proxy Factory contract, extending AbiItem[]. + * @extends SafeProxyFactoryBaseContract - Extends the generic SafeProxyFactoryBaseContract with Web3.js-specific implementation. + * + * Example subclasses: + * - SafeProxyFactoryContract_v1_4_1_Web3 extends SafeProxyFactoryBaseContractWeb3 + * - SafeProxyFactoryContract_v1_3_0_Web3 extends SafeProxyFactoryBaseContractWeb3 + * - SafeProxyFactoryContract_v1_2_0_Web3 extends SafeProxyFactoryBaseContractWeb3 + * - SafeProxyFactoryContract_v1_1_1_Web3 extends SafeProxyFactoryBaseContractWeb3 + * - SafeProxyFactoryContract_v1_0_0_Web3 extends SafeProxyFactoryBaseContractWeb3 + */ +abstract class SafeProxyFactoryBaseContractWeb3< + SafeProxyFactoryContractAbiType extends AbiItem[] +> extends SafeProxyFactoryBaseContract { + contract: Contract + adapter: Web3Adapter + + /** + * @constructor + * Constructs an instance of SafeProxyFactoryBaseContractWeb3. + * + * @param chainId - The chain ID of the contract. + * @param web3Adapter - An instance of Web3Adapter. + * @param defaultAbi - The default ABI for the Safe contract. It should be compatible with the specific version of the contract. + * @param safeVersion - The version of the Safe contract. + * @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, + web3Adapter: Web3Adapter, + defaultAbi: SafeProxyFactoryContractAbiType, + safeVersion: SafeVersion, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContractAbiType + ) { + super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + + this.adapter = web3Adapter + this.contract = web3Adapter.getContract(this.contractAddress, this.contractAbi) + } +} + +export default SafeProxyFactoryBaseContractWeb3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryWeb3Contract.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryWeb3Contract.ts deleted file mode 100644 index c0ab63576..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryWeb3Contract.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { Web3TransactionOptions } from '@safe-global/protocol-kit/adapters/web3/types' -import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' -import { Proxy_factory as SafeProxyFactory_V1_0_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.0.0/Proxy_factory' -import { Proxy_factory as SafeProxyFactory_V1_1_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.1.1/Proxy_factory' -import { Proxy_factory as SafeProxyFactory_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Proxy_factory' -import { Safe_proxy_factory as SafeProxyFactory_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Safe_proxy_factory' -import { SafeProxyFactoryContract } from '@safe-global/safe-core-sdk-types' -import { TransactionReceipt } from 'web3-core/types' - -export interface CreateProxyProps { - safeSingletonAddress: string - initializer: string - saltNonce: string - options?: Web3TransactionOptions - callback?: (txHash: string) => void -} - -class SafeProxyFactoryWeb3Contract implements SafeProxyFactoryContract { - constructor( - public contract: - | SafeProxyFactory_V1_4_1 - | SafeProxyFactory_V1_3_0 - | SafeProxyFactory_V1_1_1 - | SafeProxyFactory_V1_0_0 - ) {} - - getAddress(): Promise { - return Promise.resolve(this.contract.options.address) - } - - async proxyCreationCode(): Promise { - return this.contract.methods.proxyCreationCode().call() - } - - async createProxy({ - safeSingletonAddress, - initializer, - saltNonce, - options, - callback - }: CreateProxyProps): Promise { - if (BigInt(saltNonce) < 0) throw new Error('saltNonce must be greater than or equal to 0') - if (options && !options.gas) { - options.gas = await this.estimateGas( - 'createProxyWithNonce', - [safeSingletonAddress, initializer, saltNonce], - { - ...options - } - ) - } - const txResponse = this.contract.methods - .createProxyWithNonce(safeSingletonAddress, initializer, saltNonce) - .send(options) - - if (callback) { - const txResult = await toTxResult(txResponse) - callback(txResult.hash) - } - - const txResult: TransactionReceipt = await new Promise((resolve, reject) => - txResponse.once('receipt', (receipt: TransactionReceipt) => resolve(receipt)).catch(reject) - ) - const proxyAddress = txResult.events?.ProxyCreation?.returnValues?.proxy - if (!proxyAddress) { - throw new Error('SafeProxy was not deployed correctly') - } - return proxyAddress - } - - encode(methodName: string, params: any[]): string { - return (this.contract as any).methods[methodName](...params).encodeABI() - } - - async estimateGas( - methodName: string, - params: any[], - options: Web3TransactionOptions - ): Promise { - return ( - await (this.contract.methods as any)[methodName](...params).estimateGas(options) - ).toString() - } -} - -export default SafeProxyFactoryWeb3Contract diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_V1_0_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_V1_0_0_Web3.ts deleted file mode 100644 index 6e315f5d6..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_V1_0_0_Web3.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Proxy_factory as ProxyFactory } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.0.0/Proxy_factory' -import SafeProxyFactoryWeb3Contract from '../SafeProxyFactoryWeb3Contract' - -class SafeProxyFactoryContract_V1_0_0_Web3 extends SafeProxyFactoryWeb3Contract { - constructor(public contract: ProxyFactory) { - super(contract) - } -} - -export default SafeProxyFactoryContract_V1_0_0_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0_Web3.ts new file mode 100644 index 000000000..4f20af4d4 --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0_Web3.ts @@ -0,0 +1,166 @@ +import { TransactionReceipt } from 'web3-core/types' +import SafeProxyFactoryBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3' +import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' +import { + DeepWriteable, + Web3TransactionOptions +} from '@safe-global/protocol-kit/adapters/web3/types' +import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' +import safeProxyFactory_1_0_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.0.0/proxy_factory' +import { + EncodeSafeProxyFactoryFunction, + EstimateGasSafeProxyFactoryFunction +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import SafeProxyFactoryContract_v1_0_0_Contract, { + SafeProxyFactoryContract_v1_0_0_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0' +import { + CreateProxyProps as CreateProxyPropsGeneral, + SafeVersion +} from '@safe-global/safe-core-sdk-types' + +export interface CreateProxyProps extends CreateProxyPropsGeneral { + options?: Web3TransactionOptions +} + +/** + * SafeProxyFactoryContract_v1_0_0_Web3 is the implementation specific to the Safe Proxy Factory contract version 1.0.0. + * + * This class specializes in handling interactions with the Safe Proxy Factory contract version 1.0.0 using Web3.js. + * + * @extends SafeProxyFactoryBaseContractWeb3 - Inherits from SafeProxyFactoryBaseContractWeb3 with ABI specific to Safe Proxy Factory contract version 1.0.0. + * @implements SafeProxyFactoryContract_v1_0_0_Contract - Implements the interface specific to Safe Proxy Factory contract version 1.0.0. + */ +class SafeProxyFactoryContract_v1_0_0_Web3 + extends SafeProxyFactoryBaseContractWeb3> + implements SafeProxyFactoryContract_v1_0_0_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SafeProxyFactoryContract_v1_0_0_Web3 + * + * @param chainId - The chain ID where the contract resides. + * @param web3Adapter - An instance of Web3Adapter. + * @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 default ABI for version 1.0.0 is used. + */ + constructor( + chainId: bigint, + web3Adapter: Web3Adapter, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContract_v1_0_0_Abi + ) { + const safeVersion = '1.0.0' + const defaultAbi = + safeProxyFactory_1_0_0_ContractArtifacts.abi as DeepWriteable + + super( + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi as DeepWriteable + ) + + this.safeVersion = safeVersion + } + + encode: EncodeSafeProxyFactoryFunction = ( + functionToEncode, + args + ) => { + return this.contract.methods[functionToEncode](...args).encodeABI() + } + + estimateGas: EstimateGasSafeProxyFactoryFunction< + SafeProxyFactoryContract_v1_0_0_Abi, + Web3TransactionOptions + > = async (functionToEstimate, args, options = {}) => { + return await this.contract.methods[functionToEstimate](...args).estimateGas(options) + } + + getAddress(): Promise { + return Promise.resolve(this.contract.options.address) + } + + async proxyCreationCode(): Promise<[string]> { + return [await this.contract.methods.proxyCreationCode().call()] + } + + async proxyRuntimeCode(): Promise<[string]> { + return [await this.contract.methods.proxyRuntimeCode().call()] + } + + async createProxy(args: readonly [masterCopy: string, data: string]): Promise<[string]> { + return [await this.contract.methods.createProxy(...args).call()] + } + + async createProxyWithNonce( + args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.methods.createProxyWithNonce(...args).call()] + } + + async createProxyWithOptions({ + safeSingletonAddress, + initializer, + saltNonce, + options, + callback + }: CreateProxyProps): Promise { + const saltNonceBigInt = BigInt(saltNonce) + + if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') + if (options && !options.gas) { + options.gas = ( + await this.estimateGas( + 'createProxyWithNonce', + [safeSingletonAddress, initializer, saltNonceBigInt], + { + ...options + } + ) + ).toString() + } + + const txResponse = this.contract.methods + .createProxyWithNonce(safeSingletonAddress, initializer, saltNonce) + .send(options) + + if (callback) { + const txResult = await toTxResult(txResponse) + callback(txResult.hash) + } + + const txResult: TransactionReceipt = await new Promise((resolve, reject) => + txResponse.once('receipt', (receipt: TransactionReceipt) => resolve(receipt)).catch(reject) + ) + const proxyAddress = txResult.events?.ProxyCreation?.returnValues?.proxy + if (!proxyAddress) { + throw new Error('SafeProxy was not deployed correctly') + } + return proxyAddress + } + + // TODO: Remove this mapper after remove Typechain + mapToTypechainContract(): any { + return { + contract: this.contract, + + encode: this.encode.bind(this), + + estimateGas: async (...args: Parameters) => + (await this.estimateGas(...args)).toString(), + + createProxy: this.createProxyWithOptions.bind(this), + + getAddress: this.getAddress.bind(this), + + proxyCreationCode: async () => (await this.proxyCreationCode())[0] + } + } +} + +export default SafeProxyFactoryContract_v1_0_0_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_V1_1_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_V1_1_1_Web3.ts deleted file mode 100644 index fd5414acc..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_V1_1_1_Web3.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Proxy_factory as ProxyFactory } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.1.1/Proxy_factory' -import SafeProxyFactoryWeb3Contract from '../SafeProxyFactoryWeb3Contract' - -class SafeProxyFactoryContract_V1_1_1_Web3 extends SafeProxyFactoryWeb3Contract { - constructor(public contract: ProxyFactory) { - super(contract) - } -} - -export default SafeProxyFactoryContract_V1_1_1_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1_Web3.ts new file mode 100644 index 000000000..dbfcb05d2 --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1_Web3.ts @@ -0,0 +1,178 @@ +import { TransactionReceipt } from 'web3-core/types' +import SafeProxyFactoryBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3' +import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' +import { + DeepWriteable, + Web3TransactionOptions +} from '@safe-global/protocol-kit/adapters/web3/types' +import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' +import safeProxyFactory_1_1_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.1.1/proxy_factory' +import { + EncodeSafeProxyFactoryFunction, + EstimateGasSafeProxyFactoryFunction +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import SafeProxyFactoryContract_v1_1_1_Contract, { + SafeProxyFactoryContract_v1_1_1_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1' +import { + CreateProxyProps as CreateProxyPropsGeneral, + SafeVersion +} from '@safe-global/safe-core-sdk-types' + +export interface CreateProxyProps extends CreateProxyPropsGeneral { + options?: Web3TransactionOptions +} + +/** + * SafeProxyFactoryContract_v1_1_1_Web3 is the implementation specific to the Safe Proxy Factory contract version 1.1.1. + * + * This class specializes in handling interactions with the Safe Proxy Factory contract version 1.1.1 using Web3.js. + * + * @extends SafeProxyFactoryBaseContractWeb3 - Inherits from SafeProxyFactoryBaseContractWeb3 with ABI specific to Safe Proxy Factory contract version 1.1.1. + * @implements SafeProxyFactoryContract_v1_1_1_Contract - Implements the interface specific to Safe Proxy Factory contract version 1.1.1. + */ +class SafeProxyFactoryContract_v1_1_1_Web3 + extends SafeProxyFactoryBaseContractWeb3> + implements SafeProxyFactoryContract_v1_1_1_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SafeProxyFactoryContract_v1_1_1_Web3 + * + * @param chainId - The chain ID where the contract resides. + * @param web3Adapter - An instance of Web3Adapter. + * @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 default ABI for version 1.1.1 is used. + */ + constructor( + chainId: bigint, + web3Adapter: Web3Adapter, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContract_v1_1_1_Abi + ) { + const safeVersion = '1.1.1' + const defaultAbi = + safeProxyFactory_1_1_1_ContractArtifacts.abi as DeepWriteable + + super( + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi as DeepWriteable + ) + + this.safeVersion = safeVersion + } + + encode: EncodeSafeProxyFactoryFunction = ( + functionToEncode, + args + ) => { + return this.contract.methods[functionToEncode](...args).encodeABI() + } + + estimateGas: EstimateGasSafeProxyFactoryFunction< + SafeProxyFactoryContract_v1_1_1_Abi, + Web3TransactionOptions + > = async (functionToEstimate, args, options = {}) => { + return await this.contract.methods[functionToEstimate](...args).estimateGas(options) + } + + getAddress(): Promise { + return Promise.resolve(this.contract.options.address) + } + + async proxyCreationCode(): Promise<[string]> { + return [await this.contract.methods.proxyCreationCode().call()] + } + + async proxyRuntimeCode(): Promise<[string]> { + return [await this.contract.methods.proxyRuntimeCode().call()] + } + + async calculateCreateProxyWithNonceAddress( + args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.methods.calculateCreateProxyWithNonceAddress(...args).call()] + } + + async createProxy(args: readonly [masterCopy: string, data: string]): Promise<[string]> { + return [await this.contract.methods.createProxy(...args).call()] + } + + async createProxyWithCallback( + args: readonly [masterCopy: string, initializer: string, saltNonce: bigint, callback: string] + ): Promise<[string]> { + return [await this.contract.methods.createProxyWithCallback(...args).call()] + } + + async createProxyWithNonce( + args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.methods.createProxyWithNonce(...args).call()] + } + + async createProxyWithOptions({ + safeSingletonAddress, + initializer, + saltNonce, + options, + callback + }: CreateProxyProps): Promise { + const saltNonceBigInt = BigInt(saltNonce) + + if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') + if (options && !options.gas) { + options.gas = ( + await this.estimateGas( + 'createProxyWithNonce', + [safeSingletonAddress, initializer, saltNonceBigInt], + { + ...options + } + ) + ).toString() + } + + const txResponse = this.contract.methods + .createProxyWithNonce(safeSingletonAddress, initializer, saltNonce) + .send(options) + + if (callback) { + const txResult = await toTxResult(txResponse) + callback(txResult.hash) + } + + const txResult: TransactionReceipt = await new Promise((resolve, reject) => + txResponse.once('receipt', (receipt: TransactionReceipt) => resolve(receipt)).catch(reject) + ) + const proxyAddress = txResult.events?.ProxyCreation?.returnValues?.proxy + if (!proxyAddress) { + throw new Error('SafeProxy was not deployed correctly') + } + return proxyAddress + } + + // TODO: Remove this mapper after remove Typechain + mapToTypechainContract(): any { + return { + contract: this.contract, + + encode: this.encode.bind(this), + + estimateGas: async (...args: Parameters) => + (await this.estimateGas(...args)).toString(), + + createProxy: this.createProxyWithOptions.bind(this), + + getAddress: this.getAddress.bind(this), + + proxyCreationCode: async () => (await this.proxyCreationCode())[0] + } + } +} + +export default SafeProxyFactoryContract_v1_1_1_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_V1_3_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_V1_3_0_Web3.ts deleted file mode 100644 index 830457a44..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_V1_3_0_Web3.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Proxy_factory as ProxyFactory } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Proxy_factory' -import SafeProxyFactoryWeb3Contract from '../SafeProxyFactoryWeb3Contract' - -class SafeProxyFactoryContract_V1_3_0_Web3 extends SafeProxyFactoryWeb3Contract { - constructor(public contract: ProxyFactory) { - super(contract) - } -} - -export default SafeProxyFactoryContract_V1_3_0_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0_Web3.ts new file mode 100644 index 000000000..05f1e9ea2 --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0_Web3.ts @@ -0,0 +1,178 @@ +import { TransactionReceipt } from 'web3-core/types' +import SafeProxyFactoryBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3' +import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' +import { + DeepWriteable, + Web3TransactionOptions +} from '@safe-global/protocol-kit/adapters/web3/types' +import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' +import safeProxyFactory_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.3.0/proxy_factory' +import { + EncodeSafeProxyFactoryFunction, + EstimateGasSafeProxyFactoryFunction +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import SafeProxyFactoryContract_v1_3_0_Contract, { + SafeProxyFactoryContract_v1_3_0_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0' +import { + CreateProxyProps as CreateProxyPropsGeneral, + SafeVersion +} from '@safe-global/safe-core-sdk-types' + +export interface CreateProxyProps extends CreateProxyPropsGeneral { + options?: Web3TransactionOptions +} + +/** + * SafeProxyFactoryContract_v1_3_0_Web3 is the implementation specific to the Safe Proxy Factory contract version 1.3.0. + * + * This class specializes in handling interactions with the Safe Proxy Factory contract version 1.3.0 using Web3.js. + * + * @extends SafeProxyFactoryBaseContractWeb3 - Inherits from SafeProxyFactoryBaseContractWeb3 with ABI specific to Safe Proxy Factory contract version 1.3.0. + * @implements SafeProxyFactoryContract_v1_3_0_Contract - Implements the interface specific to Safe Proxy Factory contract version 1.3.0. + */ +class SafeProxyFactoryContract_v1_3_0_Web3 + extends SafeProxyFactoryBaseContractWeb3> + implements SafeProxyFactoryContract_v1_3_0_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SafeProxyFactoryContract_v1_3_0_Web3 + * + * @param chainId - The chain ID where the contract resides. + * @param web3Adapter - An instance of Web3Adapter. + * @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 default ABI for version 1.3.0 is used. + */ + constructor( + chainId: bigint, + web3Adapter: Web3Adapter, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContract_v1_3_0_Abi + ) { + const safeVersion = '1.3.0' + const defaultAbi = + safeProxyFactory_1_3_0_ContractArtifacts.abi as DeepWriteable + + super( + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi as DeepWriteable + ) + + this.safeVersion = safeVersion + } + + encode: EncodeSafeProxyFactoryFunction = ( + functionToEncode, + args + ) => { + return this.contract.methods[functionToEncode](...args).encodeABI() + } + + estimateGas: EstimateGasSafeProxyFactoryFunction< + SafeProxyFactoryContract_v1_3_0_Abi, + Web3TransactionOptions + > = async (functionToEstimate, args, options = {}) => { + return await this.contract.methods[functionToEstimate](...args).estimateGas(options) + } + + getAddress(): Promise { + return Promise.resolve(this.contract.options.address) + } + + async proxyCreationCode(): Promise<[string]> { + return [await this.contract.methods.proxyCreationCode().call()] + } + + async proxyRuntimeCode(): Promise<[string]> { + return [await this.contract.methods.proxyRuntimeCode().call()] + } + + async calculateCreateProxyWithNonceAddress( + args: readonly [singleton: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.methods.calculateCreateProxyWithNonceAddress(...args).call()] + } + + async createProxy(args: readonly [singleton: string, data: string]): Promise<[string]> { + return [await this.contract.methods.createProxy(...args).call()] + } + + async createProxyWithCallback( + args: readonly [singleton: string, initializer: string, saltNonce: bigint, callback: string] + ): Promise<[string]> { + return [await this.contract.methods.createProxyWithCallback(...args).call()] + } + + async createProxyWithNonce( + args: readonly [singleton: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.methods.createProxyWithNonce(...args).call()] + } + + async createProxyWithOptions({ + safeSingletonAddress, + initializer, + saltNonce, + options, + callback + }: CreateProxyProps): Promise { + const saltNonceBigInt = BigInt(saltNonce) + + if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') + if (options && !options.gas) { + options.gas = ( + await this.estimateGas( + 'createProxyWithNonce', + [safeSingletonAddress, initializer, saltNonceBigInt], + { + ...options + } + ) + ).toString() + } + + const txResponse = this.contract.methods + .createProxyWithNonce(safeSingletonAddress, initializer, saltNonce) + .send(options) + + if (callback) { + const txResult = await toTxResult(txResponse) + callback(txResult.hash) + } + + const txResult: TransactionReceipt = await new Promise((resolve, reject) => + txResponse.once('receipt', (receipt: TransactionReceipt) => resolve(receipt)).catch(reject) + ) + const proxyAddress = txResult.events?.ProxyCreation?.returnValues?.proxy + if (!proxyAddress) { + throw new Error('SafeProxy was not deployed correctly') + } + return proxyAddress + } + + // TODO: Remove this mapper after remove Typechain + mapToTypechainContract(): any { + return { + contract: this.contract, + + encode: this.encode.bind(this), + + estimateGas: async (...args: Parameters) => + (await this.estimateGas(...args)).toString(), + + createProxy: this.createProxyWithOptions.bind(this), + + getAddress: this.getAddress.bind(this), + + proxyCreationCode: async () => (await this.proxyCreationCode())[0] + } + } +} + +export default SafeProxyFactoryContract_v1_3_0_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_V1_4_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_V1_4_1_Web3.ts deleted file mode 100644 index ca079736e..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_V1_4_1_Web3.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Safe_proxy_factory as SafeProxyFactory } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Safe_proxy_factory' -import SafeProxyFactoryWeb3Contract from '../SafeProxyFactoryWeb3Contract' - -class SafeProxyFactoryContract_V1_4_1_Web3 extends SafeProxyFactoryWeb3Contract { - constructor(public contract: SafeProxyFactory) { - super(contract) - } -} - -export default SafeProxyFactoryContract_V1_4_1_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Web3.ts new file mode 100644 index 000000000..d1f49a830 --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Web3.ts @@ -0,0 +1,184 @@ +import { TransactionReceipt } from 'web3-core/types' +import SafeProxyFactoryBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3' +import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' +import { + DeepWriteable, + Web3TransactionOptions +} from '@safe-global/protocol-kit/adapters/web3/types' +import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' +import safeProxyFactory_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.4.1/safe_proxy_factory' +import { + EncodeSafeProxyFactoryFunction, + EstimateGasSafeProxyFactoryFunction +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import SafeProxyFactoryContract_v1_4_1_Contract, { + SafeProxyFactoryContract_v1_4_1_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1' +import { + CreateProxyProps as CreateProxyPropsGeneral, + SafeVersion +} from '@safe-global/safe-core-sdk-types' + +export interface CreateProxyProps extends CreateProxyPropsGeneral { + options?: Web3TransactionOptions +} + +/** + * SafeProxyFactoryContract_v1_4_1_Web3 is the implementation specific to the Safe Proxy Factory contract version 1.4.1. + * + * This class specializes in handling interactions with the Safe Proxy Factory contract version 1.4.1 using Web3.js. + * + * @extends SafeProxyFactoryBaseContractWeb3 - Inherits from SafeProxyFactoryBaseContractWeb3 with ABI specific to Safe Proxy Factory contract version 1.4.1. + * @implements SafeProxyFactoryContract_v1_4_1_Contract - Implements the interface specific to Safe Proxy Factory contract version 1.4.1. + */ +class SafeProxyFactoryContract_v1_4_1_Web3 + extends SafeProxyFactoryBaseContractWeb3> + implements SafeProxyFactoryContract_v1_4_1_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SafeProxyFactoryContract_v1_4_1_Web3 + * + * @param chainId - The chain ID where the contract resides. + * @param web3Adapter - An instance of Web3Adapter. + * @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 default ABI for version 1.4.1 is used. + */ + constructor( + chainId: bigint, + web3Adapter: Web3Adapter, + customContractAddress?: string, + customContractAbi?: SafeProxyFactoryContract_v1_4_1_Abi + ) { + const safeVersion = '1.4.1' + const defaultAbi = + safeProxyFactory_1_4_1_ContractArtifacts.abi as DeepWriteable + + super( + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi as DeepWriteable + ) + + this.safeVersion = safeVersion + } + + encode: EncodeSafeProxyFactoryFunction = ( + functionToEncode, + args + ) => { + return this.contract.methods[functionToEncode](...args).encodeABI() + } + + estimateGas: EstimateGasSafeProxyFactoryFunction< + SafeProxyFactoryContract_v1_4_1_Abi, + Web3TransactionOptions + > = async (functionToEstimate, args, options = {}) => { + return await this.contract.methods[functionToEstimate](...args).estimateGas(options) + } + + getAddress(): Promise { + return Promise.resolve(this.contract.options.address) + } + + async getChainId(): Promise<[bigint]> { + return [await this.contract.methods.getChainId().call()] + } + + async proxyCreationCode(): Promise<[string]> { + return [await this.contract.methods.proxyCreationCode().call()] + } + + async createChainSpecificProxyWithNonce( + args: readonly [singleton: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.methods.createChainSpecificProxyWithNonce(...args).call()] + } + + async proxyRuntimeCode(): Promise<[string]> { + return [await this.contract.methods.proxyRuntimeCode().call()] + } + + async calculateCreateProxyWithNonceAddress( + args: readonly [singleton: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.methods.calculateCreateProxyWithNonceAddress(...args).call()] + } + + async createProxyWithCallback( + args: readonly [singleton: string, initializer: string, saltNonce: bigint, callback: string] + ): Promise<[string]> { + return [await this.contract.methods.createProxyWithCallback(...args).call()] + } + + async createProxyWithNonce( + args: readonly [singleton: string, initializer: string, saltNonce: bigint] + ): Promise<[string]> { + return [await this.contract.methods.createProxyWithNonce(...args).call()] + } + + async createProxy({ + safeSingletonAddress, + initializer, + saltNonce, + options, + callback + }: CreateProxyProps): Promise { + const saltNonceBigInt = BigInt(saltNonce) + + if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') + if (options && !options.gas) { + options.gas = ( + await this.estimateGas( + 'createProxyWithNonce', + [safeSingletonAddress, initializer, saltNonceBigInt], + { + ...options + } + ) + ).toString() + } + + const txResponse = this.contract.methods + .createProxyWithNonce(safeSingletonAddress, initializer, saltNonce) + .send(options) + + if (callback) { + const txResult = await toTxResult(txResponse) + callback(txResult.hash) + } + + const txResult: TransactionReceipt = await new Promise((resolve, reject) => + txResponse.once('receipt', (receipt: TransactionReceipt) => resolve(receipt)).catch(reject) + ) + const proxyAddress = txResult.events?.ProxyCreation?.returnValues?.proxy + if (!proxyAddress) { + throw new Error('SafeProxy was not deployed correctly') + } + return proxyAddress + } + + // TODO: Remove this mapper after remove Typechain + mapToTypechainContract(): any { + return { + contract: this.contract, + + encode: this.encode.bind(this), + + estimateGas: async (...args: Parameters) => + (await this.estimateGas(...args)).toString(), + + createProxy: this.createProxy.bind(this), + + getAddress: this.getAddress.bind(this), + + proxyCreationCode: async () => (await this.proxyCreationCode())[0] + } + } +} + +export default SafeProxyFactoryContract_v1_4_1_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts index e3ec66337..b796ebf45 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts @@ -3,21 +3,25 @@ import SafeContract_v1_1_1_Web3 from '@safe-global/protocol-kit/adapters/web3/co import SafeContract_v1_2_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/Safe/v1.2.0/SafeContract_v1_2_0_Web3' import SafeContract_v1_3_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Web3' import SafeContract_v1_4_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Web3' +import SafeProxyFactoryContract_v1_0_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0_Web3' +import SafeProxyFactoryContract_v1_1_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1_Web3' +import SafeProxyFactoryContract_v1_3_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0_Web3' +import SafeProxyFactoryContract_v1_4_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Web3' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import { SafeContract_v1_1_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.1.1/SafeContract_v1_1_1' import { SafeContract_v1_2_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.2.0/SafeContract_v1_2_0' import { SafeContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.3.0/SafeContract_v1_3_0' import { SafeContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.4.1/SafeContract_v1_4_1' +import { SafeProxyFactoryContract_v1_0_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0' +import { SafeProxyFactoryContract_v1_1_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1' +import { SafeProxyFactoryContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0' +import { SafeProxyFactoryContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1' import { Gnosis_safe as SafeSingleton_V1_0_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.0.0/Gnosis_safe' -import { Proxy_factory as SafeProxyFactory_V1_0_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.0.0/Proxy_factory' -import { Proxy_factory as SafeProxyFactory_V1_1_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.1.1/Proxy_factory' import { Compatibility_fallback_handler as CompatibilityFallbackHandler_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Compatibility_fallback_handler' import { Create_call as CreateCall_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Create_call' -import { Proxy_factory as SafeProxyFactory_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Proxy_factory' import { Simulate_tx_accessor as SimulateTxAccessor_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Simulate_tx_accessor' import { Compatibility_fallback_handler as CompatibilityFallbackHandler_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Compatibility_fallback_handler' import { Create_call as CreateCall_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Create_call' -import { Safe_proxy_factory as SafeProxyFactory_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Safe_proxy_factory' import { Simulate_tx_accessor as SimulateTxAccessor_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Simulate_tx_accessor' import { SafeVersion, SignMessageLibContract } from '@safe-global/safe-core-sdk-types' import CompatibilityFallbackHandler_V1_3_0_Web3 from './CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandler_V1_3_0_Web3' @@ -30,10 +34,6 @@ import MultiSendContract_V1_4_1_Web3 from './MultiSend/v1.4.1/MultiSendContract_ import MultiSendCallOnlyContract_V1_3_0_Web3 from './MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Web3' import MultiSendCallOnlyContract_V1_4_1_Web3 from './MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Web3' import SafeContract_V1_0_0_Web3 from './Safe/v1.0.0/SafeContract_V1_0_0_Web3' -import SafeProxyFactoryContract_V1_0_0_Web3 from './SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_V1_0_0_Web3' -import SafeProxyFactoryContract_V1_1_1_Web3 from './SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_V1_1_1_Web3' -import SafeProxyFactoryContract_V1_3_0_Web3 from './SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_V1_3_0_Web3' -import SafeProxyFactoryContract_V1_4_1_Web3 from './SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_V1_4_1_Web3' import SignMessageLibContract_v1_3_0_Web3 from './SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Web3' import SignMessageLibContract_v1_4_1_Web3 from './SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Web3' import SimulateTxAccessorContract_V1_3_0_Web3 from './SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_V1_3_0_Web3' @@ -209,36 +209,53 @@ export async function getMultiSendCallOnlyContractInstance( } } -export function getSafeProxyFactoryContractInstance( +export async function getSafeProxyFactoryContractInstance( safeVersion: SafeVersion, - safeProxyFactoryContract: - | SafeProxyFactory_V1_4_1 - | SafeProxyFactory_V1_3_0 - | SafeProxyFactory_V1_1_1 - | SafeProxyFactory_V1_0_0 -): - | SafeProxyFactoryContract_V1_4_1_Web3 - | SafeProxyFactoryContract_V1_3_0_Web3 - | SafeProxyFactoryContract_V1_1_1_Web3 - | SafeProxyFactoryContract_V1_0_0_Web3 { + contractAddress: string, + web3Adapter: Web3Adapter, + customContractAbi?: AbiItem | AbiItem[] | undefined +) { + const chainId = await web3Adapter.getChainId() + let safeProxyFactoryContract + switch (safeVersion) { case '1.4.1': - return new SafeProxyFactoryContract_V1_4_1_Web3( - safeProxyFactoryContract as SafeProxyFactory_V1_4_1 + safeProxyFactoryContract = new SafeProxyFactoryContract_v1_4_1_Web3( + chainId, + web3Adapter, + contractAddress, + // TODO: Remove this unknown after remove Typechain + customContractAbi as unknown as SafeProxyFactoryContract_v1_4_1_Abi ) + return safeProxyFactoryContract.mapToTypechainContract() // remove this mapper after remove typechain case '1.3.0': - return new SafeProxyFactoryContract_V1_3_0_Web3( - safeProxyFactoryContract as SafeProxyFactory_V1_3_0 + safeProxyFactoryContract = new SafeProxyFactoryContract_v1_3_0_Web3( + chainId, + web3Adapter, + contractAddress, + // TODO: Remove this unknown after remove Typechain + customContractAbi as unknown as SafeProxyFactoryContract_v1_3_0_Abi ) + return safeProxyFactoryContract.mapToTypechainContract() // remove this mapper after remove typechain case '1.2.0': case '1.1.1': - return new SafeProxyFactoryContract_V1_1_1_Web3( - safeProxyFactoryContract as SafeProxyFactory_V1_1_1 + safeProxyFactoryContract = new SafeProxyFactoryContract_v1_1_1_Web3( + chainId, + web3Adapter, + contractAddress, + // TODO: Remove this unknown after remove Typechain + customContractAbi as unknown as SafeProxyFactoryContract_v1_1_1_Abi ) + return safeProxyFactoryContract.mapToTypechainContract() // remove this mapper after remove typechain case '1.0.0': - return new SafeProxyFactoryContract_V1_0_0_Web3( - safeProxyFactoryContract as SafeProxyFactory_V1_0_0 + safeProxyFactoryContract = new SafeProxyFactoryContract_v1_0_0_Web3( + chainId, + web3Adapter, + contractAddress, + // TODO: Remove this unknown after remove Typechain + customContractAbi as unknown as SafeProxyFactoryContract_v1_0_0_Abi ) + return safeProxyFactoryContract.mapToTypechainContract() // remove this mapper after remove typechain default: throw new Error('Invalid Safe version') } diff --git a/packages/protocol-kit/src/adapters/web3/index.ts b/packages/protocol-kit/src/adapters/web3/index.ts index cf9939754..5c185c070 100644 --- a/packages/protocol-kit/src/adapters/web3/index.ts +++ b/packages/protocol-kit/src/adapters/web3/index.ts @@ -3,19 +3,16 @@ import CreateCallWeb3Contract from './contracts/CreateCall/CreateCallWeb3Contrac import MultiSendBaseContractWeb3 from './contracts/MultiSend/MultiSendBaseContractWeb3' import MultiSendCallOnlyBaseContractWeb3 from './contracts/MultiSend/MultiSendCallOnlyBaseContractWeb3' import SafeContractWeb3 from './contracts/Safe/SafeContractWeb3' -import SafeProxyFactoryWeb3Contract, { - CreateProxyProps -} from './contracts/SafeProxyFactory/SafeProxyFactoryWeb3Contract' +import SafeProxyFactoryBaseContractWeb3 from './contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3' import SignMessageLibBaseContractWeb3 from './contracts/SignMessageLib/SignMessageLibBaseContractWeb3' import { Web3TransactionOptions, Web3TransactionResult } from './types' export { CreateCallWeb3Contract, - CreateProxyProps, MultiSendCallOnlyBaseContractWeb3, MultiSendBaseContractWeb3, SafeContractWeb3, - SafeProxyFactoryWeb3Contract, + SafeProxyFactoryBaseContractWeb3, SignMessageLibBaseContractWeb3, Web3Adapter, Web3AdapterConfig, diff --git a/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract.ts new file mode 100644 index 000000000..96eac92a7 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract.ts @@ -0,0 +1,98 @@ +import { + Abi, + AbiParametersToPrimitiveTypes, + ExtractAbiFunction, + ExtractAbiFunctionNames +} from 'abitype' +import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers' +import { Web3TransactionOptions } from '@safe-global/protocol-kit/adapters/web3' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * Extracts the names of read-only functions (view or pure) from a given Safe Proxy Factory contract ABI. + * + * @template SafeProxyFactoryContractAbi - The ABI of the Safe Proxy factory contract. + * @type {SafeProxyFactoryContractReadFunctions} + */ +export type SafeProxyFactoryContractReadFunctions = + ExtractAbiFunctionNames + +/** + * Extracts the names of write functions (nonpayable or payable) from a given Safe Proxy Factory contract ABI. + * + * @template SafeProxyFactoryContractAbi - The ABI of the Safe Proxy Factory contract. + * @type {SafeProxyFactoryContractWriteFunctions} + */ +export type SafeProxyFactoryContractWriteFunctions = + ExtractAbiFunctionNames + +/** + * Encodes a function call for a Safe Proxy Factory contract. + * + * @template SafeProxyFactoryContractAbi - The ABI of the Safe Proxy Factory contract. + * @template ProxyFactoryFunction - The function to encode, derived from the ABI. + */ +export type EncodeSafeProxyFactoryFunction< + SafeProxyFactoryContractAbi extends Abi, + ProxyFactoryFunction extends + ExtractAbiFunctionNames = ExtractAbiFunctionNames +> = ( + functionToEncode: ProxyFactoryFunction, + args: AbiParametersToPrimitiveTypes< + ExtractAbiFunction['inputs'], + 'inputs' + > +) => string + +/** + * Estimates the gas required for a function call on a Safe Proxy Factory contract. + * + * @template SafeProxyFactoryContractAbi - The ABI of the Safe Proxy Factory contract. + * @template ProxyFactoryFunction - The function for which gas is being estimated, derived from the ABI. + */ +export type EstimateGasSafeProxyFactoryFunction< + SafeProxyFactoryContractAbi extends Abi, // Abi of the Safe Proxy Factory Contract, + TransactionOptions extends EthersTransactionOptions | Web3TransactionOptions, + ProxyFactoryFunction extends + ExtractAbiFunctionNames = ExtractAbiFunctionNames +> = ( + functionToEncode: ProxyFactoryFunction, + args: AbiParametersToPrimitiveTypes< + ExtractAbiFunction['inputs'], + 'inputs' + >, + options?: TransactionOptions +) => Promise + +/** + * Represents the base contract type for a Safe Proxy Factory contract. + * + * @template SafeProxyFactoryContractAbi - The ABI of the Safe Proxy factory contract. + * @type {SafeProxyFactoryBaseContract} + */ +type SafeProxyFactoryBaseContract = { + [ProxyFactoryFunction in + | SafeProxyFactoryContractReadFunctions + | SafeProxyFactoryContractWriteFunctions]: ( + // parameters + args: AbiParametersToPrimitiveTypes< + ExtractAbiFunction['inputs'], + 'inputs' + > + // returned values as a Promise + ) => Promise< + AbiParametersToPrimitiveTypes< + ExtractAbiFunction['outputs'], + 'outputs' + > + > +} & { + safeVersion: SafeVersion + encode: EncodeSafeProxyFactoryFunction + estimateGas: EstimateGasSafeProxyFactoryFunction< + SafeProxyFactoryContractAbi, + EthersTransactionOptions | Web3TransactionOptions + > +} + +export default SafeProxyFactoryBaseContract diff --git a/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0.ts b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0.ts new file mode 100644 index 000000000..1dcd348a2 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0.ts @@ -0,0 +1,44 @@ +import { narrow } from 'abitype' +import safeProxyFactory_1_0_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.0.0/proxy_factory' +import SafeProxyFactoryBaseContract, { + SafeProxyFactoryContractReadFunctions, + SafeProxyFactoryContractWriteFunctions +} from '../SafeProxyFactoryBaseContract' + +const safeProxyFactoryContract_v1_0_0_AbiTypes = narrow( + safeProxyFactory_1_0_0_ContractArtifacts.abi +) + +/** + * Represents the ABI of the Safe Proxy Factory contract version 1.0.0. + * + * @type {SafeProxyFactoryContract_v1_0_0_Abi} + */ +export type SafeProxyFactoryContract_v1_0_0_Abi = typeof safeProxyFactoryContract_v1_0_0_AbiTypes + +/** + * Extracts the names of read-only functions (view or pure) specific to the Safe Proxy Factory contract version 1.0.0. + * + * @type {SafeProxyFactory_v1_0_0_Read_Functions} + */ +export type SafeProxyFactory_v1_0_0_Read_Functions = + SafeProxyFactoryContractReadFunctions + +/** + * Extracts the names of write functions (nonpayable or payable) specific to the Safe Proxy Factory contract version 1.0.0. + * + * @type {SafeProxyFactory_v1_0_0_Write_Functions} + */ +export type SafeProxyFactory_v1_0_0_Write_Functions = + SafeProxyFactoryContractWriteFunctions + +/** + * Represents the contract type for a Safe Proxy Factory contract version 1.0.0, defining read and write methods. + * Utilizes the generic SafeProxyFactoryBaseContract with the ABI specific to version 1.0.0. + * + * @type {SafeProxyFactoryContract_v1_0_0_Contract} + */ +type SafeProxyFactoryContract_v1_0_0_Contract = + SafeProxyFactoryBaseContract + +export default SafeProxyFactoryContract_v1_0_0_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1.ts b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1.ts new file mode 100644 index 000000000..3c16c3ca5 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1.ts @@ -0,0 +1,44 @@ +import { narrow } from 'abitype' +import safeProxyFactory_1_1_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.1.1/proxy_factory' +import SafeProxyFactoryBaseContract, { + SafeProxyFactoryContractReadFunctions, + SafeProxyFactoryContractWriteFunctions +} from '../SafeProxyFactoryBaseContract' + +const safeProxyFactoryContract_v1_1_1_AbiTypes = narrow( + safeProxyFactory_1_1_1_ContractArtifacts.abi +) + +/** + * Represents the ABI of the Safe Proxy Factory contract version 1.1.1. + * + * @type {SafeProxyFactoryContract_v1_1_1_Abi} + */ +export type SafeProxyFactoryContract_v1_1_1_Abi = typeof safeProxyFactoryContract_v1_1_1_AbiTypes + +/** + * Extracts the names of read-only functions (view or pure) specific to the Safe Proxy Factory contract version 1.1.1. + * + * @type {SafeProxyFactory_v1_1_1_Read_Functions} + */ +export type SafeProxyFactory_v1_1_1_Read_Functions = + SafeProxyFactoryContractReadFunctions + +/** + * Extracts the names of write functions (nonpayable or payable) specific to the Safe Proxy Factory contract version 1.1.1. + * + * @type {SafeProxyFactory_v1_1_1_Write_Functions} + */ +export type SafeProxyFactory_v1_1_1_Write_Functions = + SafeProxyFactoryContractWriteFunctions + +/** + * Represents the contract type for a Safe Proxy Factory contract version 1.1.1, defining read and write methods. + * Utilizes the generic SafeProxyFactoryBaseContract with the ABI specific to version 1.1.1. + * + * @type {SafeProxyFactoryContract_v1_1_1_Contract} + */ +type SafeProxyFactoryContract_v1_1_1_Contract = + SafeProxyFactoryBaseContract + +export default SafeProxyFactoryContract_v1_1_1_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0.ts b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0.ts new file mode 100644 index 000000000..186f0d966 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0.ts @@ -0,0 +1,44 @@ +import { narrow } from 'abitype' +import safeProxyFactory_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.3.0/proxy_factory' +import SafeProxyFactoryBaseContract, { + SafeProxyFactoryContractReadFunctions, + SafeProxyFactoryContractWriteFunctions +} from '../SafeProxyFactoryBaseContract' + +const safeProxyFactoryContract_v1_3_0_AbiTypes = narrow( + safeProxyFactory_1_3_0_ContractArtifacts.abi +) + +/** + * Represents the ABI of the Safe Proxy Factory contract version 1.3.0. + * + * @type {SafeProxyFactoryContract_v1_3_0_Abi} + */ +export type SafeProxyFactoryContract_v1_3_0_Abi = typeof safeProxyFactoryContract_v1_3_0_AbiTypes + +/** + * Extracts the names of read-only functions (view or pure) specific to the Safe Proxy Factory contract version 1.3.0. + * + * @type {SafeProxyFactory_v1_3_0_Read_Functions} + */ +export type SafeProxyFactory_v1_3_0_Read_Functions = + SafeProxyFactoryContractReadFunctions + +/** + * Extracts the names of write functions (nonpayable or payable) specific to the Safe Proxy Factory contract version 1.3.0. + * + * @type {SafeProxyFactory_v1_3_0_Write_Functions} + */ +export type SafeProxyFactory_v1_3_0_Write_Functions = + SafeProxyFactoryContractWriteFunctions + +/** + * Represents the contract type for a Safe Proxy Factory contract version 1.3.0, defining read and write methods. + * Utilizes the generic SafeProxyFactoryBaseContract with the ABI specific to version 1.3.0. + * + * @type {SafeProxyFactoryContract_v1_3_0_Contract} + */ +type SafeProxyFactoryContract_v1_3_0_Contract = + SafeProxyFactoryBaseContract + +export default SafeProxyFactoryContract_v1_3_0_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1.ts b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1.ts new file mode 100644 index 000000000..82e8cd828 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1.ts @@ -0,0 +1,44 @@ +import { narrow } from 'abitype' +import safeProxyFactory_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SafeProxyFactory/v1.4.1/safe_proxy_factory' +import SafeProxyFactoryBaseContract, { + SafeProxyFactoryContractReadFunctions, + SafeProxyFactoryContractWriteFunctions +} from '../SafeProxyFactoryBaseContract' + +const safeProxyFactoryContract_v1_4_1_AbiTypes = narrow( + safeProxyFactory_1_4_1_ContractArtifacts.abi +) + +/** + * Represents the ABI of the Safe Proxy Factory contract version 1.4.1. + * + * @type {SafeProxyFactoryContract_v1_4_1_Abi} + */ +export type SafeProxyFactoryContract_v1_4_1_Abi = typeof safeProxyFactoryContract_v1_4_1_AbiTypes + +/** + * Extracts the names of read-only functions (view or pure) specific to the Safe Proxy Factory contract version 1.4.1. + * + * @type {SafeProxyFactory_v1_4_1_Read_Functions} + */ +export type SafeProxyFactory_v1_4_1_Read_Functions = + SafeProxyFactoryContractReadFunctions + +/** + * Extracts the names of write functions (nonpayable or payable) specific to the Safe Proxy Factory contract version 1.4.1. + * + * @type {SafeProxyFactory_v1_4_1_Write_Functions} + */ +export type SafeProxyFactory_v1_4_1_Write_Functions = + SafeProxyFactoryContractWriteFunctions + +/** + * Represents the contract type for a Safe Proxy Factory contract version 1.4.1, defining read and write methods. + * Utilizes the generic SafeProxyFactoryBaseContract with the ABI specific to version 1.4.1. + * + * @type {SafeProxyFactoryContract_v1_4_1_Contract} + */ +type SafeProxyFactoryContract_v1_4_1_Contract = + SafeProxyFactoryBaseContract + +export default SafeProxyFactoryContract_v1_4_1_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.0.0/proxy_factory.ts b/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.0.0/proxy_factory.ts new file mode 100644 index 000000000..da1cc5774 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.0.0/proxy_factory.ts @@ -0,0 +1,105 @@ +export default { + defaultAddress: '0x12302fE9c02ff50939BaAaaf415fc226C078613C', + released: true, + contractName: 'ProxyFactory', + version: '1.0.0', + networkAddresses: { + '1': '0x12302fE9c02ff50939BaAaaf415fc226C078613C', + '4': '0x12302fE9c02ff50939BaAaaf415fc226C078613C', + '5': '0x12302fE9c02ff50939BaAaaf415fc226C078613C', + '42': '0x12302fE9c02ff50939BaAaaf415fc226C078613C', + '100': '0x12302fE9c02ff50939BaAaaf415fc226C078613C' + }, + abi: [ + { + constant: false, + inputs: [ + { + name: '_mastercopy', + type: 'address' + }, + { + name: 'initializer', + type: 'bytes' + }, + { + name: 'saltNonce', + type: 'uint256' + } + ], + name: 'createProxyWithNonce', + outputs: [ + { + name: 'proxy', + type: 'address' + } + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: true, + inputs: [], + name: 'proxyCreationCode', + outputs: [ + { + name: '', + type: 'bytes' + } + ], + payable: false, + stateMutability: 'pure', + type: 'function' + }, + { + constant: false, + inputs: [ + { + name: 'masterCopy', + type: 'address' + }, + { + name: 'data', + type: 'bytes' + } + ], + name: 'createProxy', + outputs: [ + { + name: 'proxy', + type: 'address' + } + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: true, + inputs: [], + name: 'proxyRuntimeCode', + outputs: [ + { + name: '', + type: 'bytes' + } + ], + payable: false, + stateMutability: 'pure', + type: 'function' + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + name: 'proxy', + type: 'address' + } + ], + name: 'ProxyCreation', + type: 'event' + } + ] +} as const diff --git a/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.1.1/proxy_factory.ts b/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.1.1/proxy_factory.ts new file mode 100644 index 000000000..24eee5e74 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.1.1/proxy_factory.ts @@ -0,0 +1,185 @@ +export default { + defaultAddress: '0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B', + released: true, + contractName: 'ProxyFactory', + version: '1.1.1', + networkAddresses: { + '1': '0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B', + '4': '0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B', + '5': '0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B', + '42': '0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B', + '88': '0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B', + '100': '0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B', + '246': '0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B', + '73799': '0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B' + }, + abi: [ + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'contract GnosisSafeProxy', + name: 'proxy', + type: 'address' + } + ], + name: 'ProxyCreation', + type: 'event' + }, + { + constant: false, + inputs: [ + { + internalType: 'address', + name: 'masterCopy', + type: 'address' + }, + { + internalType: 'bytes', + name: 'data', + type: 'bytes' + } + ], + name: 'createProxy', + outputs: [ + { + internalType: 'contract GnosisSafeProxy', + name: 'proxy', + type: 'address' + } + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: true, + inputs: [], + name: 'proxyRuntimeCode', + outputs: [ + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + payable: false, + stateMutability: 'pure', + type: 'function' + }, + { + constant: true, + inputs: [], + name: 'proxyCreationCode', + outputs: [ + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + payable: false, + stateMutability: 'pure', + type: 'function' + }, + { + constant: false, + inputs: [ + { + internalType: 'address', + name: '_mastercopy', + type: 'address' + }, + { + internalType: 'bytes', + name: 'initializer', + type: 'bytes' + }, + { + internalType: 'uint256', + name: 'saltNonce', + type: 'uint256' + } + ], + name: 'createProxyWithNonce', + outputs: [ + { + internalType: 'contract GnosisSafeProxy', + name: 'proxy', + type: 'address' + } + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [ + { + internalType: 'address', + name: '_mastercopy', + type: 'address' + }, + { + internalType: 'bytes', + name: 'initializer', + type: 'bytes' + }, + { + internalType: 'uint256', + name: 'saltNonce', + type: 'uint256' + }, + { + internalType: 'contract IProxyCreationCallback', + name: 'callback', + type: 'address' + } + ], + name: 'createProxyWithCallback', + outputs: [ + { + internalType: 'contract GnosisSafeProxy', + name: 'proxy', + type: 'address' + } + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [ + { + internalType: 'address', + name: '_mastercopy', + type: 'address' + }, + { + internalType: 'bytes', + name: 'initializer', + type: 'bytes' + }, + { + internalType: 'uint256', + name: 'saltNonce', + type: 'uint256' + } + ], + name: 'calculateCreateProxyWithNonceAddress', + outputs: [ + { + internalType: 'contract GnosisSafeProxy', + name: 'proxy', + type: 'address' + } + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + } + ] +} as const diff --git a/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.3.0/proxy_factory.ts b/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.3.0/proxy_factory.ts new file mode 100644 index 000000000..e06cf3957 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.3.0/proxy_factory.ts @@ -0,0 +1,338 @@ +export default { + defaultAddress: '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + released: true, + contractName: 'GnosisSafeProxyFactory', + version: '1.3.0', + networkAddresses: { + '1': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '3': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '4': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '5': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '10': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '11': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '12': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '18': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '25': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '28': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '30': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '31': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '39': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '40': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '41': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '42': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '44': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '46': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '50': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '51': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '56': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '57': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '61': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '63': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '69': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '71': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '81': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '82': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '83': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '97': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '100': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '106': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '108': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '111': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '122': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '123': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '137': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '148': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '155': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '169': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '246': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '250': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '255': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '280': '0xDAec33641865E4651fB43181C6DB6f7232Ee91c2', + '288': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '291': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '300': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '321': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '322': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '324': '0xDAec33641865E4651fB43181C6DB6f7232Ee91c2', + '336': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '338': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '420': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '424': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '570': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '588': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '592': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '595': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '599': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '686': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '787': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1001': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1008': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1030': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1088': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1101': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1111': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1112': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1115': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1116': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1230': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1231': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1284': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1285': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1287': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1294': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1442': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1559': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1663': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1807': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1890': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1891': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1984': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '2001': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '2002': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '2008': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '2019': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '2020': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '2021': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '2221': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '2222': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '2358': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '3737': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '4002': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '4337': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '4460': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '4689': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '4918': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '4919': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '5000': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '5001': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '5700': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '6102': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '7001': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '7332': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '7341': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '7700': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '8217': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '8453': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '9000': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '9001': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '9728': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '10000': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '10001': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '10081': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '10200': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '10243': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '11235': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '11437': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '11891': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '12357': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '13337': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '17000': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '23294': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '23295': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '42161': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '42170': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '42220': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '43113': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '43114': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '43288': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '44787': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '45000': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '47805': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '54211': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '56288': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '57000': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '58008': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '59140': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '59144': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '71401': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '71402': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '73799': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '80001': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '84531': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '200101': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '200202': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '333999': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '421611': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '421613': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '421614': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '534351': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '534352': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '534353': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '622277': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '7777777': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '11155111': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '245022926': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '245022934': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '222000222': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '333000333': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1313161554': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1313161555': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '1666600000': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '1666700000': '0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC', + '11297108099': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2', + '11297108109': '0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2' + }, + abi: [ + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'contract GnosisSafeProxy', + name: 'proxy', + type: 'address' + }, + { + indexed: false, + internalType: 'address', + name: 'singleton', + type: 'address' + } + ], + name: 'ProxyCreation', + type: 'event' + }, + { + inputs: [ + { + internalType: 'address', + name: '_singleton', + type: 'address' + }, + { + internalType: 'bytes', + name: 'initializer', + type: 'bytes' + }, + { + internalType: 'uint256', + name: 'saltNonce', + type: 'uint256' + } + ], + name: 'calculateCreateProxyWithNonceAddress', + outputs: [ + { + internalType: 'contract GnosisSafeProxy', + name: 'proxy', + type: 'address' + } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: 'singleton', + type: 'address' + }, + { + internalType: 'bytes', + name: 'data', + type: 'bytes' + } + ], + name: 'createProxy', + outputs: [ + { + internalType: 'contract GnosisSafeProxy', + name: 'proxy', + type: 'address' + } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '_singleton', + type: 'address' + }, + { + internalType: 'bytes', + name: 'initializer', + type: 'bytes' + }, + { + internalType: 'uint256', + name: 'saltNonce', + type: 'uint256' + }, + { + internalType: 'contract IProxyCreationCallback', + name: 'callback', + type: 'address' + } + ], + name: 'createProxyWithCallback', + outputs: [ + { + internalType: 'contract GnosisSafeProxy', + name: 'proxy', + type: 'address' + } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '_singleton', + type: 'address' + }, + { + internalType: 'bytes', + name: 'initializer', + type: 'bytes' + }, + { + internalType: 'uint256', + name: 'saltNonce', + type: 'uint256' + } + ], + name: 'createProxyWithNonce', + outputs: [ + { + internalType: 'contract GnosisSafeProxy', + name: 'proxy', + type: 'address' + } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [], + name: 'proxyCreationCode', + outputs: [ + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + stateMutability: 'pure', + type: 'function' + }, + { + inputs: [], + name: 'proxyRuntimeCode', + outputs: [ + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + stateMutability: 'pure', + type: 'function' + } + ] +} as const diff --git a/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.4.1/safe_proxy_factory.ts b/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.4.1/safe_proxy_factory.ts new file mode 100644 index 000000000..567f1cd6f --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/assets/SafeProxyFactory/v1.4.1/safe_proxy_factory.ts @@ -0,0 +1,171 @@ +export default { + defaultAddress: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + contractName: 'SafeProxyFactory', + version: '1.4.1', + released: true, + networkAddresses: { + '1': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '5': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '10': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '56': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '71': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '100': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '137': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '1030': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '1101': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '1442': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '4337': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '8192': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '8194': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '8453': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '10243': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '13337': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '11235': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '17000': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '42161': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '42220': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '54211': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '80001': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '84531': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67', + '11155111': '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67' + }, + abi: [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract SafeProxy', + name: 'proxy', + type: 'address' + }, + { + indexed: false, + internalType: 'address', + name: 'singleton', + type: 'address' + } + ], + name: 'ProxyCreation', + type: 'event' + }, + { + inputs: [ + { + internalType: 'address', + name: '_singleton', + type: 'address' + }, + { + internalType: 'bytes', + name: 'initializer', + type: 'bytes' + }, + { + internalType: 'uint256', + name: 'saltNonce', + type: 'uint256' + } + ], + name: 'createChainSpecificProxyWithNonce', + outputs: [ + { + internalType: 'contract SafeProxy', + name: 'proxy', + type: 'address' + } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '_singleton', + type: 'address' + }, + { + internalType: 'bytes', + name: 'initializer', + type: 'bytes' + }, + { + internalType: 'uint256', + name: 'saltNonce', + type: 'uint256' + }, + { + internalType: 'contract IProxyCreationCallback', + name: 'callback', + type: 'address' + } + ], + name: 'createProxyWithCallback', + outputs: [ + { + internalType: 'contract SafeProxy', + name: 'proxy', + type: 'address' + } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '_singleton', + type: 'address' + }, + { + internalType: 'bytes', + name: 'initializer', + type: 'bytes' + }, + { + internalType: 'uint256', + name: 'saltNonce', + type: 'uint256' + } + ], + name: 'createProxyWithNonce', + outputs: [ + { + internalType: 'contract SafeProxy', + name: 'proxy', + type: 'address' + } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [], + name: 'getChainId', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'proxyCreationCode', + outputs: [ + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + stateMutability: 'pure', + type: 'function' + } + ] +} as const diff --git a/packages/protocol-kit/src/index.ts b/packages/protocol-kit/src/index.ts index 4b59f7518..ad1f1b72e 100644 --- a/packages/protocol-kit/src/index.ts +++ b/packages/protocol-kit/src/index.ts @@ -1,7 +1,6 @@ import Safe from './Safe' import { CreateCallEthersContract, - CreateProxyProps as CreateEthersProxyProps, EthersAdapter, EthersAdapterConfig, EthersTransactionOptions, @@ -9,16 +8,15 @@ import { MultiSendBaseContractEthers, MultiSendCallOnlyBaseContractEthers, SafeContractEthers, - SafeProxyFactoryEthersContract, + SafeProxyFactoryBaseContractEthers, SignMessageLibBaseContractEthers } from './adapters/ethers' import { CreateCallWeb3Contract, - CreateProxyProps as CreateWeb3ProxyProps, MultiSendBaseContractWeb3, MultiSendCallOnlyBaseContractWeb3, SafeContractWeb3, - SafeProxyFactoryWeb3Contract, + SafeProxyFactoryBaseContractWeb3, SignMessageLibBaseContractWeb3, Web3Adapter, Web3AdapterConfig, @@ -90,9 +88,7 @@ export { CreateCallEthersContract, CreateCallWeb3Contract, createERC20TokenTransferTransaction, - CreateEthersProxyProps, CreateTransactionProps, - CreateWeb3ProxyProps, DEFAULT_SAFE_VERSION, DeploySafeProps, EthSafeSignature, @@ -116,8 +112,8 @@ export { SafeDeploymentConfig, SafeFactory, SafeFactoryConfig, - SafeProxyFactoryEthersContract, - SafeProxyFactoryWeb3Contract, + SafeProxyFactoryBaseContractEthers, + SafeProxyFactoryBaseContractWeb3, SafeTransactionOptionalProps, SignMessageLibBaseContractEthers, SignMessageLibBaseContractWeb3,