diff --git a/packages/protocol-kit/scripts/generateTypechainFiles.ts b/packages/protocol-kit/scripts/generateTypechainFiles.ts index 3913e3e00..f7e8d3ed5 100644 --- a/packages/protocol-kit/scripts/generateTypechainFiles.ts +++ b/packages/protocol-kit/scripts/generateTypechainFiles.ts @@ -1,27 +1,10 @@ import { execSync } from 'child_process' -import { existsSync, mkdirSync, readdir } from 'fs' -import path from 'path' // Directories where the Typechain files will be generated const outDirSrc = 'typechain/src/' -const typeChainDirectorySrcPath = path.join(__dirname, `../${outDirSrc}`) - -const outDirBuild = 'dist/typechain/src/' -const typeChainDirectoryBuildPath = path.join(__dirname, `../${outDirBuild}`) const outDirTests = 'typechain/tests/' -// Contract list for which the Typechain files will be generated -// Will be included in dist/ folder -const safeContractsPath = '../../node_modules/@safe-global/safe-deployments/dist/assets' - -const safeContracts_V1_4_1 = [ - `${safeContractsPath}/v1.4.1/compatibility_fallback_handler.json` -].join(' ') -const safeContracts_V1_3_0 = [ - `${safeContractsPath}/v1.3.0/compatibility_fallback_handler.json` -].join(' ') - // Won't be included in dist/ folder const safeContractsTestV1_4_1Path = '../../node_modules/@safe-global/safe-contracts-v1.4.1/build/artifacts/contracts' @@ -55,47 +38,7 @@ function generateTypechainFiles( console.log(`Generated typechain ${typechainVersion} at ${outDir}`) } -// Copy Typechain files with the right extension (.d.ts -> .ts) allows them to be included in the build folder -function moveTypechainFiles(inDir: string, outDir: string): void { - readdir(`${inDir}`, (error, files) => { - if (error) { - console.log(error) - } - if (!existsSync(`${outDir}`)) { - mkdirSync(`${outDir}`, { recursive: true }) - } - files.forEach((file) => { - const pattern = /.d.ts/ - if (!file.match(pattern)) { - return - } - execSync(`cp ${inDir}/${file} ${outDir}/${file}`) - }) - }) -} - -// Contracts v1.0.0 + v1.1.1 + v1.2.0 are migrated to Abitype already, so they're not included in here function generateTypes(typechainTarget: string) { - // Src - generateTypechainFiles( - typechainTarget, - `${outDirSrc}${typechainTarget}/v1.4.1`, - safeContracts_V1_4_1 - ) - generateTypechainFiles( - typechainTarget, - `${outDirSrc}${typechainTarget}/v1.3.0`, - safeContracts_V1_3_0 - ) - moveTypechainFiles( - `${typeChainDirectorySrcPath}${typechainTarget}/v1.4.1`, - `${typeChainDirectoryBuildPath}${typechainTarget}/v1.4.1` - ) - moveTypechainFiles( - `${typeChainDirectorySrcPath}${typechainTarget}/v1.3.0`, - `${typeChainDirectoryBuildPath}${typechainTarget}/v1.3.0` - ) - // Tests generateTypechainFiles( typechainTarget, diff --git a/packages/protocol-kit/src/adapters/BaseContract.ts b/packages/protocol-kit/src/adapters/BaseContract.ts new file mode 100644 index 000000000..5bde1c870 --- /dev/null +++ b/packages/protocol-kit/src/adapters/BaseContract.ts @@ -0,0 +1,61 @@ +import { contractName, getContractDeployment } from '@safe-global/protocol-kit/contracts/config' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * Abstract class BaseContract serves as a base for creating a 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 BaseContractEthers, BaseContractWeb3, and BaseContractViem. + * It includes the core logic for selecting the appropriate ABI and the address from contract deployments. + * + * @template ContractAbiType - The ABI associated with the contract. + * + * Example subclasses extending this base class: + * - BaseContractEthers extends BaseContract + * - BaseContractWeb3 extends BaseContract + * - BaseContractViem extends BaseContract + */ +abstract class BaseContract { + contractAbi: ContractAbiType + contractAddress: string + + abstract contractName: contractName + abstract safeVersion: SafeVersion + + abstract contract: unknown // This needs to be implemented for each adapter. + abstract adapter: unknown // This needs to be implemented for each adapter. + + /** + * Constructs a new BaseContract instance. + * + * @param contractName - The contract name. + * @param chainId - The chain ID of the contract. + * @param defaultAbi - The hardcoded ABI of the contract. + * @param safeVersion - The version of the 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( + contractName: contractName, + chainId: bigint, + defaultAbi: ContractAbiType, + safeVersion: SafeVersion, + customContractAddress?: string, + customContractAbi?: ContractAbiType + ) { + const deployment = getContractDeployment(safeVersion, chainId, contractName) + + const contractAddress = customContractAddress || deployment?.defaultAddress + + if (!contractAddress) { + throw new Error('Invalid contract address') + } + + this.contractAddress = contractAddress + this.contractAbi = + customContractAbi || + (deployment?.abi as ContractAbiType) || // 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 BaseContract diff --git a/packages/protocol-kit/src/adapters/CreateCallBaseContract.ts b/packages/protocol-kit/src/adapters/CreateCallBaseContract.ts deleted file mode 100644 index 14e738769..000000000 --- a/packages/protocol-kit/src/adapters/CreateCallBaseContract.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { contractName, getContractDeployment } from '@safe-global/protocol-kit/contracts/config' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' - -/** - * Abstract class CreateCallBaseContract serves as a base for creating a CreateCallBaseContract 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 CreateCallBaseContractEthers, CreateCallBaseContractWeb3, and CreateCallBaseContractViem. - * It includes the core logic for selecting the appropriate ABI and the address from CreateCall deployments. - * - * @template CreateCallContractAbiType - The ABI associated with the CreateCall contract. - * - * Example subclasses extending this base class: - * - CreateCallBaseContractEthers extends CreateCallBaseContract - * - CreateCallBaseContractWeb3 extends CreateCallBaseContract - * - CreateCallBaseContractViem extends CreateCallBaseContract - */ -abstract class CreateCallBaseContract { - contractAbi: CreateCallContractAbiType - contractAddress: string - - contractName: contractName - abstract safeVersion: SafeVersion - - abstract contract: unknown // This needs to be implemented for each adapter. - abstract adapter: unknown // This needs to be implemented for each adapter. - - /** - * Constructs a new CreateCallBaseContract instance. - * - * @param chainId - The chain ID of the contract. - * @param defaultAbi - The hardcoded ABI of the CreateCall contract. - * @param safeVersion - The version of the CreateCall 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: CreateCallContractAbiType, - safeVersion: SafeVersion, - customContractAddress?: string, - customContractAbi?: CreateCallContractAbiType - ) { - this.contractName = 'createCallVersion' - - const deployment = getContractDeployment(safeVersion, chainId, this.contractName) - - const contractAddress = customContractAddress || deployment?.defaultAddress - - if (!contractAddress) { - throw new Error('Invalid contract address') - } - - this.contractAddress = contractAddress - this.contractAbi = - customContractAbi || - (deployment?.abi as CreateCallContractAbiType) || // 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 CreateCallBaseContract diff --git a/packages/protocol-kit/src/adapters/MultiSendBaseContract.ts b/packages/protocol-kit/src/adapters/MultiSendBaseContract.ts deleted file mode 100644 index d2db07790..000000000 --- a/packages/protocol-kit/src/adapters/MultiSendBaseContract.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { contractName, getContractDeployment } from '@safe-global/protocol-kit/contracts/config' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' - -/** - * Abstract class MultiSendBaseContract serves as a base for creating a MultiSendBaseContract 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 MultiSendBaseContractEthers, MultiSendBaseContractWeb3, and MultiSendBaseContractViem. - * It includes the core logic for selecting the appropriate ABI and the address from MultiSend deployments. - * - * @template MultiSendContractAbiType - The ABI associated with the MultiSend contract. - * - * Example subclasses extending this base class: - * - MultiSendBaseContractEthers extends MultiSendBaseContract - * - MultiSendBaseContractWeb3 extends MultiSendBaseContract - * - MultiSendBaseContractViem extends MultiSendBaseContract - */ -abstract class MultiSendBaseContract { - contractAbi: MultiSendContractAbiType - contractAddress: string - - contractName: contractName - abstract safeVersion: SafeVersion - - abstract contract: unknown // This needs to be implemented for each adapter. - abstract adapter: unknown // This needs to be implemented for each adapter. - - /** - * Constructs a new MultiSendBaseContract instance. - * - * @param chainId - The chain ID of the contract. - * @param defaultAbi - The hardcoded ABI of the MultiSend contract. - * @param safeVersion - The version of the MultiSend 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: MultiSendContractAbiType, - safeVersion: SafeVersion, - customContractAddress?: string, - customContractAbi?: MultiSendContractAbiType - ) { - this.contractName = 'multiSendVersion' - - const deployment = getContractDeployment(safeVersion, chainId, this.contractName) - - const contractAddress = customContractAddress || deployment?.defaultAddress - - if (!contractAddress) { - throw new Error('Invalid contract address') - } - - this.contractAddress = contractAddress - this.contractAbi = - customContractAbi || - (deployment?.abi as MultiSendContractAbiType) || // 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 MultiSendBaseContract diff --git a/packages/protocol-kit/src/adapters/MultiSendCallOnlyBaseContract.ts b/packages/protocol-kit/src/adapters/MultiSendCallOnlyBaseContract.ts deleted file mode 100644 index f3c82952c..000000000 --- a/packages/protocol-kit/src/adapters/MultiSendCallOnlyBaseContract.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { contractName, getContractDeployment } from '@safe-global/protocol-kit/contracts/config' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' - -/** - * Abstract class MultiSendCallOnlyBaseContract serves as a base for creating a MultiSendCallOnlyBaseContract 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 MultiSendCallOnlyBaseContractEthers, MultiSendCallOnlyBaseContractWeb3, and MultiSendCallOnlyBaseContractViem. - * It includes the core logic for selecting the appropriate ABI and the address from MultiSendCallOnly deployments. - * - * @template MultiSendCallOnlyContractAbiType - The ABI associated with the MultiSendCallOnly contract. - * - * Example subclasses extending this base class: - * - MultiSendCallOnlyBaseContractEthers extends MultiSendCallOnlyBaseContract - * - MultiSendCallOnlyBaseContractWeb3 extends MultiSendCallOnlyBaseContract - * - MultiSendCallOnlyBaseContractViem extends MultiSendCallOnlyBaseContract - */ -abstract class MultiSendCallOnlyBaseContract { - contractAbi: MultiSendCallOnlyContractAbiType - contractAddress: string - - contractName: contractName - abstract safeVersion: SafeVersion - - abstract contract: unknown // This needs to be implemented for each adapter. - abstract adapter: unknown // This needs to be implemented for each adapter. - - /** - * Constructs a new MultiSendCallOnlyBaseContract instance. - * - * @param chainId - The chain ID of the contract. - * @param defaultAbi - The hardcoded ABI of the MultiSendCallOnly contract. - * @param safeVersion - The version of the MultiSendCallOnly 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: MultiSendCallOnlyContractAbiType, - safeVersion: SafeVersion, - customContractAddress?: string, - customContractAbi?: MultiSendCallOnlyContractAbiType - ) { - this.contractName = 'multiSendCallOnlyVersion' - - const deployment = getContractDeployment(safeVersion, chainId, this.contractName) - - const contractAddress = customContractAddress || deployment?.defaultAddress - - if (!contractAddress) { - throw new Error('Invalid contract address') - } - - this.contractAddress = contractAddress - this.contractAbi = - customContractAbi || - (deployment?.abi as MultiSendCallOnlyContractAbiType) || // 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 MultiSendCallOnlyBaseContract diff --git a/packages/protocol-kit/src/adapters/SafeBaseContract.ts b/packages/protocol-kit/src/adapters/SafeBaseContract.ts deleted file mode 100644 index 896b06f4b..000000000 --- a/packages/protocol-kit/src/adapters/SafeBaseContract.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { - contractName, - safeDeploymentsL1ChainIds, - getContractDeployment -} from '@safe-global/protocol-kit/contracts/config' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' - -/** - * Abstract class SafeBaseContract serves as a base for creating a Safe contract for a specific adapter (Ethers.js, Web3.js, or viem.js) - * This class is designed to be extended by adapter-specific abstract classes, such as SafeBaseContractEthers, SafeBaseContractWeb3, and SafeBaseContractViem. - * It includes the core logic for selecting the appropriate ABI and the address from Safe deployments and determining the correct L1 or L2 contract version of the Safe. - * - * @template SafeContractAbiType - The ABI associated with the Safe contract. - * - * Example subclasses extending this base class: - * - SafeBaseContractEthers extends SafeBaseContract - * - SafeBaseContractWeb3 extends SafeBaseContract - * - SafeBaseContractViem extends SafeBaseContract - */ -abstract class SafeBaseContract { - contractAbi: SafeContractAbiType - contractAddress: string - - contractName: contractName - abstract safeVersion: SafeVersion - - abstract contract: unknown // This needs to be implemented for each adapter. - abstract adapter: unknown // This needs to be implemented for each adapter. - - /** - * Constructs a new SafeBaseContract instance. - * - * @param chainId - The chain ID of the contract. - * @param defaultAbi - The hardcoded ABI of the Safe contract. - * @param safeVersion - The version of the Safe contract. - * @param isL1SafeSingleton - Flag to indicate if it's an L1 Safe Singleton. - * @param customContractAddress - Optional custom address for the contract. - * @param customContractAbi - Optional custom ABI for the contract. - * @throws Will throw an error if the contract address is invalid. - */ - constructor( - chainId: bigint, - defaultAbi: SafeContractAbiType, - safeVersion: SafeVersion, - isL1SafeSingleton = false, - customContractAddress?: string, - customContractAbi?: SafeContractAbiType - ) { - const isL1Contract = safeDeploymentsL1ChainIds.includes(chainId) || isL1SafeSingleton - - this.contractName = isL1Contract ? 'safeSingletonVersion' : 'safeSingletonL2Version' - - const singletonDeployment = getContractDeployment(safeVersion, chainId, this.contractName) - - const contractAddress = customContractAddress || singletonDeployment?.defaultAddress - - if (!contractAddress) { - throw new Error('Invalid SafeProxy contract address') - } - - this.contractAddress = contractAddress - this.contractAbi = - customContractAbi || - (singletonDeployment?.abi as SafeContractAbiType) || // this cast is required because abi is set as any[] in safe-deployments - defaultAbi // if no customAbi and no abi is present in the safe-deployments we use our hardcoded abi - } -} - -export default SafeBaseContract diff --git a/packages/protocol-kit/src/adapters/SafeProxyFactoryBaseContract.ts b/packages/protocol-kit/src/adapters/SafeProxyFactoryBaseContract.ts deleted file mode 100644 index 649eca305..000000000 --- a/packages/protocol-kit/src/adapters/SafeProxyFactoryBaseContract.ts +++ /dev/null @@ -1,58 +0,0 @@ -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/SignMessageLibBaseContract.ts b/packages/protocol-kit/src/adapters/SignMessageLibBaseContract.ts deleted file mode 100644 index e8d0cd628..000000000 --- a/packages/protocol-kit/src/adapters/SignMessageLibBaseContract.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { contractName, getContractDeployment } from '@safe-global/protocol-kit/contracts/config' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' - -/** - * Abstract class SignMessageLibBaseContract serves as a base for creating a SignMessageLibBaseContract 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 SignMessageLibBaseContractEthers, SignMessageLibBaseContractWeb3, and SignMessageLibBaseContractViem. - * It includes the core logic for selecting the appropriate ABI and the address from SignMessageLib deployments. - * - * @template SignMessageLibContractAbiType - The ABI associated with the SignMessageLib contract. - * - * Example subclasses extending this base class: - * - SignMessageLibBaseContractEthers extends SignMessageLibBaseContract - * - SignMessageLibBaseContractWeb3 extends SignMessageLibBaseContract - * - SignMessageLibBaseContractViem extends SignMessageLibBaseContract - */ -abstract class SignMessageLibBaseContract { - contractAbi: SignMessageLibContractAbiType - contractAddress: string - - contractName: contractName - abstract safeVersion: SafeVersion - - abstract contract: unknown // This needs to be implemented for each adapter. - abstract adapter: unknown // This needs to be implemented for each adapter. - - /** - * Constructs a new SignMessageLibBaseContract instance. - * - * @param chainId - The chain ID of the contract. - * @param defaultAbi - The hardcoded ABI of the SignMessageLib contract. - * @param safeVersion - The version of the SignMessageLib 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: SignMessageLibContractAbiType, - safeVersion: SafeVersion, - customContractAddress?: string, - customContractAbi?: SignMessageLibContractAbiType - ) { - this.contractName = 'signMessageLibVersion' - - const deployment = getContractDeployment(safeVersion, chainId, this.contractName) - - const contractAddress = customContractAddress || deployment?.defaultAddress - - if (!contractAddress) { - throw new Error('Invalid contract address') - } - - this.contractAddress = contractAddress - this.contractAbi = - customContractAbi || - (deployment?.abi as SignMessageLibContractAbiType) || // 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 SignMessageLibBaseContract diff --git a/packages/protocol-kit/src/adapters/SimulateTxAccessorBaseContract.ts b/packages/protocol-kit/src/adapters/SimulateTxAccessorBaseContract.ts deleted file mode 100644 index 023c2b659..000000000 --- a/packages/protocol-kit/src/adapters/SimulateTxAccessorBaseContract.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { contractName, getContractDeployment } from '@safe-global/protocol-kit/contracts/config' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' - -/** - * Abstract class SimulateTxAccessorBaseContract serves as a base for creating a SimulateTxAccessorBaseContract 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 SimulateTxAccessorBaseContractEthers, SimulateTxAccessorBaseContractWeb3, and SimulateTxAccessorBaseContractViem. - * It includes the core logic for selecting the appropriate ABI and the address from SimulateTxAccessor deployments. - * - * @template SimulateTxAccessorContractAbiType - The ABI associated with the SimulateTxAccessor contract. - * - * Example subclasses extending this base class: - * - SimulateTxAccessorBaseContractEthers extends SimulateTxAccessorBaseContract - * - SimulateTxAccessorBaseContractWeb3 extends SimulateTxAccessorBaseContract - * - SimulateTxAccessorBaseContractViem extends SimulateTxAccessorBaseContract - */ -abstract class SimulateTxAccessorBaseContract { - contractAbi: SimulateTxAccessorContractAbiType - contractAddress: string - - contractName: contractName - abstract safeVersion: SafeVersion - - abstract contract: unknown // This needs to be implemented for each adapter. - abstract adapter: unknown // This needs to be implemented for each adapter. - - /** - * Constructs a new SimulateTxAccessorBaseContract instance. - * - * @param chainId - The chain ID of the contract. - * @param defaultAbi - The hardcoded ABI of the SimulateTxAccessor contract. - * @param safeVersion - The version of the SimulateTxAccessor 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: SimulateTxAccessorContractAbiType, - safeVersion: SafeVersion, - customContractAddress?: string, - customContractAbi?: SimulateTxAccessorContractAbiType - ) { - this.contractName = 'simulateTxAccessorVersion' - - const deployment = getContractDeployment(safeVersion, chainId, this.contractName) - - const contractAddress = customContractAddress || deployment?.defaultAddress - - if (!contractAddress) { - throw new Error('Invalid contract address') - } - - this.contractAddress = contractAddress - this.contractAbi = - customContractAbi || - (deployment?.abi as SimulateTxAccessorContractAbiType) || // 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 SimulateTxAccessorBaseContract diff --git a/packages/protocol-kit/src/adapters/ethers/EthersAdapter.ts b/packages/protocol-kit/src/adapters/ethers/EthersAdapter.ts index 755150307..ff72b48aa 100644 --- a/packages/protocol-kit/src/adapters/ethers/EthersAdapter.ts +++ b/packages/protocol-kit/src/adapters/ethers/EthersAdapter.ts @@ -1,5 +1,6 @@ import { generateTypedData, validateEip3770Address } from '@safe-global/protocol-kit/utils' import { + CompatibilityFallbackHandlerContract, CreateCallContract, EIP712TypedDataMessage, EIP712TypedDataTx, @@ -12,7 +13,6 @@ import { SimulateTxAccessorContract } from '@safe-global/safe-core-sdk-types' import { ethers, TransactionResponse, AbstractSigner, Provider } from 'ethers' -import CompatibilityFallbackHandlerContractEthers from './contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerEthersContract' import SafeContractEthers from './contracts/Safe/SafeContractEthers' import { getCompatibilityFallbackHandlerContractInstance, @@ -185,19 +185,20 @@ class EthersAdapter implements EthAdapter { async getCompatibilityFallbackHandlerContract({ safeVersion, singletonDeployment, - customContractAddress - }: GetContractProps): Promise { + customContractAddress, + customContractAbi + }: GetContractProps): Promise { const chainId = await this.getChainId() const contractAddress = customContractAddress ?? singletonDeployment?.networkAddresses[chainId.toString()] if (!contractAddress) { throw new Error('Invalid CompatibilityFallbackHandler contract address') } - const signerOrProvider = this.#signer || this.#provider return getCompatibilityFallbackHandlerContractInstance( safeVersion, contractAddress, - signerOrProvider + this, + customContractAbi ) } diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/BaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/BaseContractEthers.ts new file mode 100644 index 000000000..dc62a1b11 --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/BaseContractEthers.ts @@ -0,0 +1,87 @@ +import { Abi } from 'abitype' +import { Contract, ContractRunner, InterfaceAbi } from 'ethers' + +import { contractName } from '@safe-global/protocol-kit/contracts/config' +import BaseContract from '@safe-global/protocol-kit/adapters/BaseContract' +import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import { + EncodeFunction, + EstimateGasFunction, + GetAddressFunction +} from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' +import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers/types' + +/** + * Abstract class BaseContractEthers extends BaseContract to specifically integrate with the Ethers.js v6 library. + * It is designed to be instantiated for different contracts. + * + * This abstract class sets up the Ethers v6 Contract object that interacts with the smart contract. + * + * Subclasses of BaseContractEthers are expected to represent specific contracts. + * + * @template ContractAbiType - The ABI type specific to the version of the contract, extending InterfaceAbi from Ethers. + * @extends BaseContract - Extends the generic BaseContract with Ethers-specific implementation. + * + * Example subclasses: + * - SafeBaseContractEthers extends BaseContractEthers + * - CreateCallBaseContractEthers extends BaseContractEthers + * - SafeProxyFactoryBaseContractEthers extends BaseContractEthers + */ +abstract class BaseContractEthers< + ContractAbiType extends InterfaceAbi & Abi +> extends BaseContract { + contract: Contract + adapter: EthersAdapter + + /** + * @constructor + * Constructs an instance of BaseContractEthers. + * + * @param contractName - The contract name. + * @param chainId - The chain ID of the contract. + * @param ethersAdapter - An instance of EthersAdapter. + * @param defaultAbi - The default ABI for the 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( + contractName: contractName, + chainId: bigint, + ethersAdapter: EthersAdapter, + defaultAbi: ContractAbiType, + safeVersion: SafeVersion, + customContractAddress?: string, + customContractAbi?: ContractAbiType, + runner?: ContractRunner | null + ) { + super(contractName, chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + + this.adapter = ethersAdapter + this.contract = new Contract( + this.contractAddress, + this.contractAbi, + runner || this.adapter.getSigner() + ) + } + + getAddress: GetAddressFunction = () => { + return this.contract.getAddress() + } + + encode: EncodeFunction = (functionToEncode, args) => { + return this.contract.interface.encodeFunctionData(functionToEncode, args as ReadonlyArray) + } + + estimateGas: EstimateGasFunction = ( + functionToEstimate, + args, + options = {} + ) => { + const contractMethodToEstimate = this.contract.getFunction(functionToEstimate) + return contractMethodToEstimate.estimateGas(...(args as ReadonlyArray), options) + } +} + +export default BaseContractEthers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContractEthers.ts new file mode 100644 index 000000000..8dab8970f --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContractEthers.ts @@ -0,0 +1,64 @@ +import { Abi } from 'abitype' +import { ContractRunner, InterfaceAbi } from 'ethers' + +import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' +import BaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/BaseContractEthers' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import { contractName } from '@safe-global/protocol-kit/contracts/config' + +/** + * Abstract class CompatibilityFallbackHandlerBaseContractEthers extends BaseContractEthers to specifically integrate with the CompatibilityFallbackHandler contract. + * It is designed to be instantiated for different versions of the Safe contract. + * + * Subclasses of CompatibilityFallbackHandlerBaseContractEthers are expected to represent specific versions of the contract. + * + * @template CompatibilityFallbackHandlerContractAbiType - The ABI type specific to the version of the CompatibilityFallbackHandler contract, extending InterfaceAbi from Ethers. + * @extends BaseContractEthers - Extends the generic BaseContractEthers. + * + * Example subclasses: + * - CompatibilityFallbackHandlerContract_v1_4_1_Ethers extends CompatibilityFallbackHandlerBaseContractEthers + * - CompatibilityFallbackHandlerContract_v1_3_0_Ethers extends CompatibilityFallbackHandlerBaseContractEthers + */ +abstract class CompatibilityFallbackHandlerBaseContractEthers< + CompatibilityFallbackHandlerContractAbiType extends InterfaceAbi & Abi +> extends BaseContractEthers { + contractName: contractName + + /** + * @constructor + * Constructs an instance of CompatibilityFallbackHandlerBaseContractEthers. + * + * @param chainId - The chain ID of the contract. + * @param ethersAdapter - An instance of EthersAdapter. + * @param defaultAbi - The default ABI for the CompatibilityFallbackHandler 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: CompatibilityFallbackHandlerContractAbiType, + safeVersion: SafeVersion, + customContractAddress?: string, + customContractAbi?: CompatibilityFallbackHandlerContractAbiType, + runner?: ContractRunner | null + ) { + const contractName = 'compatibilityFallbackHandler' + + super( + contractName, + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi, + runner + ) + + this.contractName = contractName + } +} + +export default CompatibilityFallbackHandlerBaseContractEthers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerEthersContract.ts b/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerEthersContract.ts deleted file mode 100644 index 8046de1ea..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerEthersContract.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { - Compatibility_fallback_handler as CompatibilityFallbackHandler_V1_3_0, - Compatibility_fallback_handlerInterface as CompatibilityFallbackHandlerInterface -} from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/Compatibility_fallback_handler' -import { Compatibility_fallback_handler as CompatibilityFallbackHandler_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/Compatibility_fallback_handler' -import { CompatibilityFallbackHandlerContract } from '@safe-global/safe-core-sdk-types' - -abstract class CompatibilityFallbackHandlerEthersContract - implements CompatibilityFallbackHandlerContract -{ - constructor( - public contract: CompatibilityFallbackHandler_V1_4_1 | CompatibilityFallbackHandler_V1_3_0 - ) {} - - getAddress(): Promise { - return this.contract.getAddress() - } - - encode: CompatibilityFallbackHandlerInterface['encodeFunctionData'] = ( - methodName: any, - params: any - ): string => { - return this.contract.interface.encodeFunctionData(methodName, params) - } -} - -export default CompatibilityFallbackHandlerEthersContract diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0_Ethers.ts new file mode 100644 index 000000000..1975af8d4 --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0_Ethers.ts @@ -0,0 +1,46 @@ +import CompatibilityFallbackHandlerBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContractEthers' +import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' +import CompatibilityFallbackHandlerContract_v1_3_0_Contract, { + CompatibilityFallbackHandlerContract_v1_3_0_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0' +import CompatibilityFallbackHandler_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.3.0/compatibility_fallback_handler' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * CompatibilityFallbackHandlerContract_v1_3_0_Ethers is the implementation specific to the CompatibilityFallbackHandler contract version 1.3.0. + * + * This class specializes in handling interactions with the CompatibilityFallbackHandler contract version 1.3.0 using Ethers.js v6. + * + * @extends CompatibilityFallbackHandlerBaseContractEthers - Inherits from CompatibilityFallbackHandlerBaseContractEthers with ABI specific to CompatibilityFallbackHandler contract version 1.3.0. + * @implements CompatibilityFallbackHandlerContract_v1_3_0_Contract - Implements the interface specific to CompatibilityFallbackHandler contract version 1.3.0. + */ +class CompatibilityFallbackHandlerContract_v1_3_0_Ethers + extends CompatibilityFallbackHandlerBaseContractEthers + implements CompatibilityFallbackHandlerContract_v1_3_0_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of CompatibilityFallbackHandlerContract_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 CompatibilityFallbackHandler 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?: CompatibilityFallbackHandlerContract_v1_3_0_Abi + ) { + const safeVersion = '1.3.0' + const defaultAbi = CompatibilityFallbackHandler_1_3_0_ContractArtifacts.abi + + super(chainId, ethersAdapter, defaultAbi, safeVersion, customContractAddress, customContractAbi) + + this.safeVersion = safeVersion + } +} + +export default CompatibilityFallbackHandlerContract_v1_3_0_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandler_V1_3_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandler_V1_3_0_Ethers.ts deleted file mode 100644 index 77d36778e..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandler_V1_3_0_Ethers.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Compatibility_fallback_handler as CompatibilityFallbackHandler } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/Compatibility_fallback_handler' -import CompatibilityFallbackHandlerEthersContract from '../CompatibilityFallbackHandlerEthersContract' - -class CompatibilityFallbackHandler_V1_3_0_Ethers extends CompatibilityFallbackHandlerEthersContract { - constructor(public contract: CompatibilityFallbackHandler) { - super(contract) - } -} - -export default CompatibilityFallbackHandler_V1_3_0_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1_Ethers.ts new file mode 100644 index 000000000..5fedeb643 --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1_Ethers.ts @@ -0,0 +1,46 @@ +import CompatibilityFallbackHandlerBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContractEthers' +import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' +import CompatibilityFallbackHandlerContract_v1_4_1_Contract, { + CompatibilityFallbackHandlerContract_v1_4_1_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1' +import CompatibilityFallbackHandler_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.4.1/compatibility_fallback_handler' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * CompatibilityFallbackHandlerContract_v1_4_1_Ethers is the implementation specific to the CompatibilityFallbackHandler contract version 1.4.1. + * + * This class specializes in handling interactions with the CompatibilityFallbackHandler contract version 1.4.1 using Ethers.js v6. + * + * @extends CompatibilityFallbackHandlerBaseContractEthers - Inherits from CompatibilityFallbackHandlerBaseContractEthers with ABI specific to CompatibilityFallbackHandler contract version 1.4.1. + * @implements CompatibilityFallbackHandlerContract_v1_4_1_Contract - Implements the interface specific to CompatibilityFallbackHandler contract version 1.4.1. + */ +class CompatibilityFallbackHandlerContract_v1_4_1_Ethers + extends CompatibilityFallbackHandlerBaseContractEthers + implements CompatibilityFallbackHandlerContract_v1_4_1_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of CompatibilityFallbackHandlerContract_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 CompatibilityFallbackHandler 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?: CompatibilityFallbackHandlerContract_v1_4_1_Abi + ) { + const safeVersion = '1.4.1' + const defaultAbi = CompatibilityFallbackHandler_1_4_1_ContractArtifacts.abi + + super(chainId, ethersAdapter, defaultAbi, safeVersion, customContractAddress, customContractAbi) + + this.safeVersion = safeVersion + } +} + +export default CompatibilityFallbackHandlerContract_v1_4_1_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandler_V1_4_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandler_V1_4_1_Ethers.ts deleted file mode 100644 index 0a1e9d9ae..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandler_V1_4_1_Ethers.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Compatibility_fallback_handler as CompatibilityFallbackHandler } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/Compatibility_fallback_handler' -import CompatibilityFallbackHandlerEthersContract from '../CompatibilityFallbackHandlerEthersContract' - -class CompatibilityFallbackHandler_V1_4_1_Ethers extends CompatibilityFallbackHandlerEthersContract { - constructor(public contract: CompatibilityFallbackHandler) { - super(contract) - } -} - -export default CompatibilityFallbackHandler_V1_4_1_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/CreateCallBaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/CreateCallBaseContractEthers.ts index 375eaf99e..93c5c1c83 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/CreateCallBaseContractEthers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/CreateCallBaseContractEthers.ts @@ -1,29 +1,28 @@ -import { Contract, ContractRunner, InterfaceAbi } from 'ethers' +import { Abi } from 'abitype' +import { ContractRunner, InterfaceAbi } from 'ethers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' -import CreateCallBaseContract from '@safe-global/protocol-kit/adapters/CreateCallBaseContract' +import BaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/BaseContractEthers' import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import { contractName } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class CreateCallBaseContractEthers extends CreateCallBaseContract to specifically integrate with the Ethers.js v6 library. + * Abstract class CreateCallBaseContractEthers extends BaseContractEthers to specifically integrate with the CreateCall contract. * 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 CreateCall contract version. - * * Subclasses of CreateCallBaseContractEthers are expected to represent specific versions of the contract. * * @template CreateCallContractAbiType - The ABI type specific to the version of the CreateCall contract, extending InterfaceAbi from Ethers. - * @extends CreateCallBaseContract - Extends the generic CreateCallBaseContract with Ethers-specific implementation. + * @extends BaseContractEthers - Extends the generic BaseContractEthers. * * Example subclasses: * - CreateCallContract_v1_4_1_Ethers extends CreateCallBaseContractEthers * - CreateCallContract_v1_3_0_Ethers extends CreateCallBaseContractEthers */ abstract class CreateCallBaseContractEthers< - CreateCallContractAbiType extends InterfaceAbi -> extends CreateCallBaseContract { - contract: Contract - adapter: EthersAdapter + CreateCallContractAbiType extends InterfaceAbi & Abi +> extends BaseContractEthers { + contractName: contractName /** * @constructor @@ -45,14 +44,20 @@ abstract class CreateCallBaseContractEthers< customContractAbi?: CreateCallContractAbiType, runner?: ContractRunner | null ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'createCallVersion' - this.adapter = ethersAdapter - this.contract = new Contract( - this.contractAddress, - this.contractAbi, - runner || this.adapter.getSigner() + super( + contractName, + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi, + runner ) + + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/v1.3.0/CreateCallContract_v1_3_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/v1.3.0/CreateCallContract_v1_3_0_Ethers.ts index a773b7490..9e35cff40 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/v1.3.0/CreateCallContract_v1_3_0_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/v1.3.0/CreateCallContract_v1_3_0_Ethers.ts @@ -1,20 +1,13 @@ import CreateCallBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/CreateCall/CreateCallBaseContractEthers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' -import { - EthersTransactionOptions, - EthersTransactionResult -} from '@safe-global/protocol-kit/adapters/ethers/types' +import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers/types' import CreateCallContract_v1_3_0_Contract, { CreateCallContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/v1.3.0/CreateCallContract_v1_3_0' import CreateCall_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CreateCall/v1.3.0/create_call' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeCreateCallFunction, - EstimateGasCreateCallFunction, - GetAddressCreateCallFunction -} from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/CreateCallBaseContract' import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' +import { AdapterSpecificContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' /** * CreateCallContract_V1_3_0_Ethers is the implementation specific to the CreateCall contract version 1.3.0. @@ -26,7 +19,7 @@ import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' */ class CreateCallContract_V1_3_0_Ethers extends CreateCallBaseContractEthers - implements CreateCallContract_v1_3_0_Contract + implements CreateCallContract_v1_3_0_Contract { safeVersion: SafeVersion @@ -52,44 +45,37 @@ class CreateCallContract_V1_3_0_Ethers this.safeVersion = safeVersion } - getAddress: GetAddressCreateCallFunction = () => { - return this.contract.getAddress() - } - - encode: EncodeCreateCallFunction = (functionToEncode, args) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } - - estimateGas: EstimateGasCreateCallFunction< - CreateCallContract_v1_3_0_Abi, - EthersTransactionOptions - > = (functionToEstimate, args, options = {}) => { - const contractMethodToEstimate = this.contract.getFunction(functionToEstimate) - - return contractMethodToEstimate.estimateGas(...args, options) - } - - async performCreate( - args: readonly [value: bigint, deploymentData: string], - options?: EthersTransactionOptions - ): Promise { - if (options && !options.gasLimit) { - options.gasLimit = (await this.estimateGas('performCreate', args, { ...options })).toString() + /** + * @param args - Array[value, deploymentData] + * @param options - EthersTransactionOptions + * @returns Promise + */ + performCreate: AdapterSpecificContractFunction = + async (args, options) => { + if (options && !options.gasLimit) { + options.gasLimit = ( + await this.estimateGas('performCreate', [...args], { ...options }) + ).toString() + } + const txResponse = await this.contract.performCreate(...args, { ...options }) + return toTxResult(txResponse, options) } - const txResponse = await this.contract.performCreate(...args, { ...options }) - return toTxResult(txResponse, options) - } - async performCreate2( - args: readonly [value: bigint, deploymentData: string, salt: string], - options?: EthersTransactionOptions - ): Promise { - if (options && !options.gasLimit) { - options.gasLimit = (await this.estimateGas('performCreate2', args, { ...options })).toString() + /** + * @param args - Array[value, deploymentData, salt] + * @param options - EthersTransactionOptions + * @returns Promise + */ + performCreate2: AdapterSpecificContractFunction = + async (args, options) => { + if (options && !options.gasLimit) { + options.gasLimit = ( + await this.estimateGas('performCreate2', [...args], { ...options }) + ).toString() + } + const txResponse = await this.contract.performCreate2(...args) + return toTxResult(txResponse, options) } - const txResponse = await this.contract.performCreate2(...args) - return toTxResult(txResponse, options) - } // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): any { diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/v1.4.1/CreateCallContract_v1_4_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/v1.4.1/CreateCallContract_v1_4_1_Ethers.ts index 591082b4b..5788e31f5 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/v1.4.1/CreateCallContract_v1_4_1_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/CreateCall/v1.4.1/CreateCallContract_v1_4_1_Ethers.ts @@ -1,20 +1,13 @@ import CreateCallBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/CreateCall/CreateCallBaseContractEthers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' -import { - EthersTransactionOptions, - EthersTransactionResult -} from '@safe-global/protocol-kit/adapters/ethers/types' +import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers/types' import CreateCallContract_v1_4_1_Contract, { CreateCallContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/v1.4.1/CreateCallContract_v1_4_1' import CreateCall_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CreateCall/v1.4.1/create_call' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeCreateCallFunction, - EstimateGasCreateCallFunction, - GetAddressCreateCallFunction -} from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/CreateCallBaseContract' import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' +import { AdapterSpecificContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' /** * CreateCallContract_V1_4_1_Ethers is the implementation specific to the CreateCall contract version 1.4.1. @@ -26,7 +19,7 @@ import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' */ class CreateCallContract_V1_4_1_Ethers extends CreateCallBaseContractEthers - implements CreateCallContract_v1_4_1_Contract + implements CreateCallContract_v1_4_1_Contract { safeVersion: SafeVersion @@ -52,44 +45,37 @@ class CreateCallContract_V1_4_1_Ethers this.safeVersion = safeVersion } - getAddress: GetAddressCreateCallFunction = () => { - return this.contract.getAddress() - } - - encode: EncodeCreateCallFunction = (functionToEncode, args) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } - - estimateGas: EstimateGasCreateCallFunction< - CreateCallContract_v1_4_1_Abi, - EthersTransactionOptions - > = (functionToEstimate, args, options = {}) => { - const contractMethodToEstimate = this.contract.getFunction(functionToEstimate) - - return contractMethodToEstimate.estimateGas(...args, options) - } - - async performCreate( - args: readonly [value: bigint, deploymentData: string], - options?: EthersTransactionOptions - ): Promise { - if (options && !options.gasLimit) { - options.gasLimit = (await this.estimateGas('performCreate', args, { ...options })).toString() + /** + * @param args - Array[value, deploymentData] + * @param options - EthersTransactionOptions + * @returns Promise + */ + performCreate: AdapterSpecificContractFunction = + async (args, options) => { + if (options && !options.gasLimit) { + options.gasLimit = ( + await this.estimateGas('performCreate', [...args], { ...options }) + ).toString() + } + const txResponse = await this.contract.performCreate(...args, { ...options }) + return toTxResult(txResponse, options) } - const txResponse = await this.contract.performCreate(...args, { ...options }) - return toTxResult(txResponse, options) - } - async performCreate2( - args: readonly [value: bigint, deploymentData: string, salt: string], - options?: EthersTransactionOptions - ): Promise { - if (options && !options.gasLimit) { - options.gasLimit = (await this.estimateGas('performCreate2', args, { ...options })).toString() + /** + * @param args - Array[value, deploymentData, salt] + * @param options - EthersTransactionOptions + * @returns Promise + */ + performCreate2: AdapterSpecificContractFunction = + async (args, options) => { + if (options && !options.gasLimit) { + options.gasLimit = ( + await this.estimateGas('performCreate2', [...args], { ...options }) + ).toString() + } + const txResponse = await this.contract.performCreate2(...args) + return toTxResult(txResponse, options) } - const txResponse = await this.contract.performCreate2(...args) - return toTxResult(txResponse, options) - } // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): any { diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/MultiSendBaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/MultiSendBaseContractEthers.ts index ddaecb927..a03e1a621 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/MultiSendBaseContractEthers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/MultiSendBaseContractEthers.ts @@ -1,29 +1,28 @@ -import { Contract, InterfaceAbi } from 'ethers' +import { Abi } from 'abitype' +import { InterfaceAbi } from 'ethers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import MultiSendBaseContract from '@safe-global/protocol-kit/adapters/MultiSendBaseContract' +import BaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/BaseContractEthers' +import { contractName } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class MultiSendBaseContractEthers extends MultiSendBaseContract to specifically integrate with the Ethers.js v6 library. + * Abstract class MultiSendBaseContractEthers extends BaseContractEthers to specifically integrate with the MultiSend contract. * It is designed to be instantiated for different versions of the MultiSend contract. * - * This abstract class sets up the Ethers v6 Contract object that interacts with a MultiSend contract version. - * * Subclasses of MultiSendBaseContractEthers are expected to represent specific versions of the MultiSend contract. * * @template MultiSendContractAbiType - The ABI type specific to the version of the MultiSend contract, extending InterfaceAbi from Ethers. - * @extends MultiSendBaseContract - Extends the generic MultiSendBaseContract with Ethers-specific implementation. + * @extends BaseContractEthers - Extends the generic BaseContractEthers. * * Example subclasses: * - MultiSendContract_v1_4_1_Ethers extends MultiSendBaseContractEthers * - MultiSendContract_v1_3_0_Ethers extends MultiSendBaseContractEthers */ abstract class MultiSendBaseContractEthers< - MultiSendContractAbiType extends InterfaceAbi -> extends MultiSendBaseContract { - contract: Contract - adapter: EthersAdapter + MultiSendContractAbiType extends InterfaceAbi & Abi +> extends BaseContractEthers { + contractName: contractName /** * @constructor @@ -44,10 +43,19 @@ abstract class MultiSendBaseContractEthers< customContractAddress?: string, customContractAbi?: MultiSendContractAbiType ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'multiSendVersion' + + super( + contractName, + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi + ) - this.adapter = ethersAdapter - this.contract = new Contract(this.contractAddress, this.contractAbi, this.adapter.getSigner()) + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/MultiSendCallOnlyBaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/MultiSendCallOnlyBaseContractEthers.ts index 539e8207f..af007b4ad 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/MultiSendCallOnlyBaseContractEthers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/MultiSendCallOnlyBaseContractEthers.ts @@ -1,29 +1,28 @@ -import { Contract, InterfaceAbi } from 'ethers' +import { Abi } from 'abitype' +import { InterfaceAbi } from 'ethers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import MultiSendCallOnlyBaseContract from '@safe-global/protocol-kit/adapters/MultiSendCallOnlyBaseContract' +import BaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/BaseContractEthers' +import { contractName } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class MultiSendCallOnlyBaseContractEthers extends MultiSendCallOnlyBaseContract to specifically integrate with the Ethers.js v6 library. + * Abstract class MultiSendCallOnlyBaseContractEthers extends BaseContractEthers to specifically integrate with the MultiSendCallOnly contract. * It is designed to be instantiated for different versions of the MultiSendCallOnly contract. * - * This abstract class sets up the Ethers v6 Contract object that interacts with a MultiSendCallOnly contract version. - * * Subclasses of MultiSendCallOnlyBaseContractEthers are expected to represent specific versions of the MultiSendCallOnly contract. * * @template MultiSendCallOnlyContractAbiType - The ABI type specific to the version of the MultiSendCallOnly contract, extending InterfaceAbi from Ethers. - * @extends MultiSendCallOnlyBaseContract - Extends the generic MultiSendCallOnlyBaseContract with Ethers-specific implementation. + * @extends BaseContractEthers - Extends the generic BaseContractEthers. * * Example subclasses: * - MultiSendCallOnlyContract_v1_4_1_Ethers extends MultiSendCallOnlyBaseContractEthers * - MultiSendCallOnlyContract_v1_3_0_Ethers extends MultiSendCallOnlyBaseContractEthers */ abstract class MultiSendCallOnlyBaseContractEthers< - MultiSendCallOnlyContractAbiType extends InterfaceAbi -> extends MultiSendCallOnlyBaseContract { - contract: Contract - adapter: EthersAdapter + MultiSendCallOnlyContractAbiType extends InterfaceAbi & Abi +> extends BaseContractEthers { + contractName: contractName /** * @constructor @@ -44,10 +43,19 @@ abstract class MultiSendCallOnlyBaseContractEthers< customContractAddress?: string, customContractAbi?: MultiSendCallOnlyContractAbiType ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'multiSendCallOnlyVersion' + + super( + contractName, + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi + ) - this.adapter = ethersAdapter - this.contract = new Contract(this.contractAddress, this.contractAbi, this.adapter.getSigner()) + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.1.1/MultiSendContract_V1_1_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.1.1/MultiSendContract_V1_1_1_Ethers.ts index a8fbae004..ecbdab96b 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.1.1/MultiSendContract_V1_1_1_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.1.1/MultiSendContract_V1_1_1_Ethers.ts @@ -5,10 +5,6 @@ import MultiSendContract_v1_1_1_Contract, { } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.1.1/MultiSendContract_v1_1_1' import multisend_1_1_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/MultiSend/v1.1.1/multi_send' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeMultiSendFunction, - GetAddressMultiSendFunction -} from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/MultiSendBaseContract' /** * MultiSendContract_v1_1_1_Ethers is the implementation specific to the MultiSend contract version 1.1.1. @@ -45,14 +41,6 @@ class MultiSendContract_v1_1_1_Ethers this.safeVersion = safeVersion } - - getAddress: GetAddressMultiSendFunction = () => { - return this.contract.getAddress() - } - - encode: EncodeMultiSendFunction = (functionToEncode, args) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } } export default MultiSendContract_v1_1_1_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Ethers.ts index 36fcbd227..21b4a2540 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Ethers.ts @@ -5,10 +5,6 @@ import MultiSendCallOnlyContract_v1_3_0_Contract, { } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.3.0/MultiSendCallOnlyContract_v1_3_0' import multiSendCallOnly_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/MultiSend/v1.3.0/multi_send_call_only' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeMultiSendCallOnlyFunction, - GetAddressMultiSendCallOnlyFunction -} from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/MultiSendCallOnlyBaseContract' /** * MultiSendCallOnlyContract_v1_3_0_Ethers is the implementation specific to the MultiSendCallOnly contract version 1.3.0. @@ -45,17 +41,6 @@ class MultiSendCallOnlyContract_v1_3_0_Ethers this.safeVersion = safeVersion } - - getAddress: GetAddressMultiSendCallOnlyFunction = () => { - return this.contract.getAddress() - } - - encode: EncodeMultiSendCallOnlyFunction = ( - functionToEncode, - args - ) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } } export default MultiSendCallOnlyContract_v1_3_0_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.3.0/MultiSendContract_V1_3_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.3.0/MultiSendContract_V1_3_0_Ethers.ts index bd16e8e2c..6af16523b 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.3.0/MultiSendContract_V1_3_0_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.3.0/MultiSendContract_V1_3_0_Ethers.ts @@ -5,10 +5,6 @@ import MultiSendContract_v1_3_0_Contract, { } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.3.0/MultiSendContract_v1_3_0' import multisend_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/MultiSend/v1.3.0/multi_send' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeMultiSendFunction, - GetAddressMultiSendFunction -} from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/MultiSendBaseContract' /** * MultiSendContract_v1_3_0_Ethers is the implementation specific to the MultiSend contract version 1.3.0. @@ -45,14 +41,6 @@ class MultiSendContract_v1_3_0_Ethers this.safeVersion = safeVersion } - - getAddress: GetAddressMultiSendFunction = () => { - return this.contract.getAddress() - } - - encode: EncodeMultiSendFunction = (functionToEncode, args) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } } export default MultiSendContract_v1_3_0_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Ethers.ts index 133b6c905..b4f9126e4 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Ethers.ts @@ -5,10 +5,6 @@ import MultiSendCallOnlyContract_v1_4_1_Contract, { } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.4.1/MultiSendCallOnlyContract_v1_4_1' import multiSendCallOnly_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/MultiSend/v1.4.1/multi_send_call_only' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeMultiSendCallOnlyFunction, - GetAddressMultiSendCallOnlyFunction -} from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/MultiSendCallOnlyBaseContract' /** * MultiSendCallOnlyContract_v1_4_1_Ethers is the implementation specific to the MultiSend contract version 1.4.1. @@ -45,17 +41,6 @@ class MultiSendCallOnlyContract_v1_4_1_Ethers this.safeVersion = safeVersion } - - getAddress: GetAddressMultiSendCallOnlyFunction = () => { - return this.contract.getAddress() - } - - encode: EncodeMultiSendCallOnlyFunction = ( - functionToEncode, - args - ) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } } export default MultiSendCallOnlyContract_v1_4_1_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.4.1/MultiSendContract_V1_4_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.4.1/MultiSendContract_V1_4_1_Ethers.ts index 19099b281..6ef0db279 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.4.1/MultiSendContract_V1_4_1_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/MultiSend/v1.4.1/MultiSendContract_V1_4_1_Ethers.ts @@ -5,10 +5,6 @@ import MultiSendContract_v1_4_1_Contract, { } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.4.1/MultiSendContract_v1_4_1' import multisend_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/MultiSend/v1.4.1/multi_send' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeMultiSendFunction, - GetAddressMultiSendFunction -} from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/MultiSendBaseContract' /** * MultiSendContract_v1_4_1_Ethers is the implementation specific to the MultiSend contract version 1.4.1. @@ -45,14 +41,6 @@ class MultiSendContract_v1_4_1_Ethers this.safeVersion = safeVersion } - - getAddress: GetAddressMultiSendFunction = () => { - return this.contract.getAddress() - } - - encode: EncodeMultiSendFunction = (functionToEncode, args) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } } export default MultiSendContract_v1_4_1_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/SafeBaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/SafeBaseContractEthers.ts index e06cff88a..02ac88eb9 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/SafeBaseContractEthers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/SafeBaseContractEthers.ts @@ -1,19 +1,19 @@ -import { Contract, InterfaceAbi } from 'ethers' +import { Abi } from 'abitype' +import { InterfaceAbi } from 'ethers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import SafeBaseContract from '@safe-global/protocol-kit/adapters/SafeBaseContract' +import BaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/BaseContractEthers' +import { contractName, safeDeploymentsL1ChainIds } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class SafeBaseContractEthers extends SafeBaseContract to specifically integrate with the Ethers.js v6 library. + * Abstract class SafeBaseContractEthers extends BaseContractEthers to specifically integrate with the Safe contract. * It is designed to be instantiated for different versions of the Safe contract. * - * This abstract class sets up the Ethers v6 Contract object that interacts with a Safe contract version. - * * Subclasses of SafeBaseContractEthers are expected to represent specific versions of the Safe contract. * * @template SafeContractAbiType - The ABI type specific to the version of the Safe contract, extending InterfaceAbi from Ethers. - * @extends SafeBaseContract - Extends the generic SafeBaseContract with Ethers-specific implementation. + * @extends BaseContractEthers - Extends the generic BaseContractEthers. * * Example subclasses: * - SafeContract_v1_4_1_Ethers extends SafeBaseContractEthers @@ -23,10 +23,9 @@ import SafeBaseContract from '@safe-global/protocol-kit/adapters/SafeBaseContrac * - SafeContract_v1_0_0_Ethers extends SafeBaseContractEthers */ abstract class SafeBaseContractEthers< - SafeContractAbiType extends InterfaceAbi -> extends SafeBaseContract { - contract: Contract - adapter: EthersAdapter + SafeContractAbiType extends InterfaceAbi & Abi +> extends BaseContractEthers { + contractName: contractName /** * @constructor @@ -49,17 +48,20 @@ abstract class SafeBaseContractEthers< customContractAddress?: string, customContractAbi?: SafeContractAbiType ) { + const isL1Contract = safeDeploymentsL1ChainIds.includes(chainId) || isL1SafeSingleton + const contractName = isL1Contract ? 'safeSingletonVersion' : 'safeSingletonL2Version' + super( + contractName, chainId, + ethersAdapter, defaultAbi, safeVersion, - isL1SafeSingleton, customContractAddress, customContractAbi ) - this.adapter = ethersAdapter - this.contract = new Contract(this.contractAddress, this.contractAbi, this.adapter.getSigner()) + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.0.0/SafeContract_v1_0_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.0.0/SafeContract_v1_0_0_Ethers.ts index f3238e92d..ee09086f7 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.0.0/SafeContract_v1_0_0_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.0.0/SafeContract_v1_0_0_Ethers.ts @@ -5,14 +5,11 @@ import { EthersTransactionResult } from '@safe-global/protocol-kit/adapters/ethers/types' import SafeContract_v1_0_0_Contract, { - SafeContract_v1_0_0_Abi + SafeContract_v1_0_0_Abi, + SafeContract_v1_0_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.0.0/SafeContract_v1_0_0' import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' import safe_1_0_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.0.0/gnosis_safe' -import { - EncodeSafeFunction, - EstimateGasSafeFunction -} from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' import { sameString } from '@safe-global/protocol-kit/utils' import { SafeTransaction, SafeTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -63,118 +60,139 @@ class SafeContract_v1_0_0_Ethers } /* ----- Specific v1.0.0 properties ----- */ - async DOMAIN_SEPARATOR_TYPEHASH(): Promise<[string]> { - return [await this.contract.DOMAIN_SEPARATOR_TYPEHASH()] - } + DOMAIN_SEPARATOR_TYPEHASH: SafeContract_v1_0_0_Function<'DOMAIN_SEPARATOR_TYPEHASH'> = + async () => { + return [await this.contract.DOMAIN_SEPARATOR_TYPEHASH()] + } - async SENTINEL_MODULES(): Promise<[string]> { + SENTINEL_MODULES: SafeContract_v1_0_0_Function<'SENTINEL_MODULES'> = async () => { return [await this.contract.SENTINEL_MODULES()] } - async SENTINEL_OWNERS(): Promise<[string]> { + SENTINEL_OWNERS: SafeContract_v1_0_0_Function<'SENTINEL_OWNERS'> = async () => { return [await this.contract.SENTINEL_OWNERS()] } - async SAFE_MSG_TYPEHASH(): Promise<[string]> { + SAFE_MSG_TYPEHASH: SafeContract_v1_0_0_Function<'SAFE_MSG_TYPEHASH'> = async () => { return [await this.contract.SAFE_MSG_TYPEHASH()] } - async SAFE_TX_TYPEHASH(): Promise<[string]> { + SAFE_TX_TYPEHASH: SafeContract_v1_0_0_Function<'SAFE_TX_TYPEHASH'> = async () => { return [await this.contract.SAFE_TX_TYPEHASH()] } /* ----- End of specific v1.0.0 properties ----- */ - async NAME(): Promise<[string]> { + /** + * @returns Array[contractName] + */ + NAME: SafeContract_v1_0_0_Function<'NAME'> = async () => { return [await this.contract.NAME()] } - async VERSION(): Promise<[SafeVersion]> { + /** + * @returns Array[safeContractVersion] + */ + VERSION: SafeContract_v1_0_0_Function<'VERSION'> = async () => { return [await this.contract.VERSION()] } - async approvedHashes([owner, txHash]: readonly [string, string]): Promise<[bigint]> { - return [await this.contract.approvedHashes(owner, txHash)] + /** + * @param args - Array[owner, txHash] + * @returns Array[approvedHashes] + */ + approvedHashes: SafeContract_v1_0_0_Function<'approvedHashes'> = async (args) => { + return [await this.contract.approvedHashes(...args)] } - async domainSeparator(): Promise<[string]> { + /** + * @returns Array[domainSeparator] + */ + domainSeparator: SafeContract_v1_0_0_Function<'domainSeparator'> = async () => { return [await this.contract.domainSeparator()] } - async getModules(): Promise<[string[]]> { + /** + * Returns array of modules. + * @returns Array[Array[modules]] + */ + getModules: SafeContract_v1_0_0_Function<'getModules'> = async () => { return [await this.contract.getModules()] } - async getOwners(): Promise<[string[]]> { + /** + * Returns the list of Safe owner accounts. + * @returns Array[Array[owners]] + */ + getOwners: SafeContract_v1_0_0_Function<'getOwners'> = async () => { return [await this.contract.getOwners()] } - async getThreshold(): Promise<[bigint]> { + /** + * Returns the Safe threshold. + * @returns Array[threshold] + */ + getThreshold: SafeContract_v1_0_0_Function<'getThreshold'> = async () => { return [await this.contract.getThreshold()] } - async isOwner(args: readonly [address: string]): Promise<[boolean]> { + /** + * Checks if a specific address is an owner of the current Safe. + * @param args - Array[address] + * @returns Array[isOwner] + */ + isOwner: SafeContract_v1_0_0_Function<'isOwner'> = async (args) => { return [await this.contract.isOwner(...args)] } - async nonce(): Promise<[bigint]> { + /** + * Returns the Safe nonce. + * @returns Array[nonce] + */ + nonce: SafeContract_v1_0_0_Function<'nonce'> = async () => { return [await this.contract.nonce()] } - async signedMessages(args: readonly [messageHash: string]): Promise<[bigint]> { + /** + * @param args - Array[messageHash] + * @returns Array[signedMessages] + */ + signedMessages: SafeContract_v1_0_0_Function<'signedMessages'> = async (args) => { return [await this.contract.signedMessages(...args)] } - async getMessageHash(args: readonly [message: string]): Promise<[string]> { + /** + * Returns hash of a message that can be signed by owners. + * @param args - Array[message] + * @returns Array[messageHash] + */ + getMessageHash: SafeContract_v1_0_0_Function<'getMessageHash'> = async (args) => { return [await this.contract.getMessageHash(...args)] } - async encodeTransactionData( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns the bytes that are hashed to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[encodedData] + */ + encodeTransactionData: SafeContract_v1_0_0_Function<'encodeTransactionData'> = async (args) => { return [await this.contract.encodeTransactionData(...args)] } - async getTransactionHash( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns hash to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[transactionHash] + */ + getTransactionHash: SafeContract_v1_0_0_Function<'getTransactionHash'> = async (args) => { return [await this.contract.getTransactionHash(...args)] } - encode: EncodeSafeFunction = (functionToEncode, args) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } - - estimateGas: EstimateGasSafeFunction = ( - functionToEstimate, - args, - options = {} - ) => { - return this.contract.getFunction(functionToEstimate).estimateGas(...args, options) - } - - // Custom method (not defined in the Safe Contract) + /** + * Marks a hash as approved. This can be used to validate a hash that is used by a signature. + * @param hash - The hash that should be marked as approved for signatures that are verified by this contract. + * @param options - Optional transaction options. + * @returns Transaction result. + */ async approveHash( hash: string, options?: EthersTransactionOptions @@ -185,12 +203,12 @@ class SafeContract_v1_0_0_Ethers return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) - getAddress(): Promise { - return this.contract.getAddress() - } - - // Custom method (not defined in the Safe Contract) + /** + * Executes a transaction. + * @param safeTransaction - The Safe transaction to execute. + * @param options - Transaction options. + * @returns Transaction result. + */ async execTransaction( safeTransaction: SafeTransaction, options?: EthersTransactionOptions @@ -231,7 +249,11 @@ class SafeContract_v1_0_0_Ethers return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) + /** + * Checks if a specific Safe module is enabled for the current Safe. + * @param moduleAddress - The module address to check. + * @returns True, if the module with the given address is enabled. + */ async isModuleEnabled(moduleAddress: string): Promise { const [modules] = await this.getModules() const isModuleEnabled = modules.some((enabledModuleAddress: string) => @@ -240,7 +262,12 @@ class SafeContract_v1_0_0_Ethers return isModuleEnabled } - // Custom method (not defined in the Safe Contract) + /** + * Checks whether a given Safe transaction can be executed successfully with no errors. + * @param safeTransaction - The Safe transaction to check. + * @param options - Optional transaction options. + * @returns True, if the given transactions is valid. + */ async isValidTransaction( safeTransaction: SafeTransaction, options: EthersTransactionOptions = {} diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.1.1/SafeContract_v1_1_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.1.1/SafeContract_v1_1_1_Ethers.ts index 56f53ee64..59da05f6c 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.1.1/SafeContract_v1_1_1_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.1.1/SafeContract_v1_1_1_Ethers.ts @@ -5,14 +5,11 @@ import { EthersTransactionResult } from '@safe-global/protocol-kit/adapters/ethers/types' import SafeContract_v1_1_1_Contract, { - SafeContract_v1_1_1_Abi + SafeContract_v1_1_1_Abi, + SafeContract_v1_1_1_Function } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.1.1/SafeContract_v1_1_1' import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' import safe_1_1_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.1.1/gnosis_safe' -import { - EncodeSafeFunction, - EstimateGasSafeFunction -} from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' import { sameString } from '@safe-global/protocol-kit/utils' import { SafeTransaction, SafeTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -62,104 +59,127 @@ class SafeContract_v1_1_1_Ethers this.safeVersion = safeVersion } - async NAME(): Promise<[string]> { + /** + * @returns Array[contractName] + */ + NAME: SafeContract_v1_1_1_Function<'NAME'> = async () => { return [await this.contract.NAME()] } - async VERSION(): Promise<[SafeVersion]> { + /** + * @returns Array[safeContractVersion] + */ + VERSION: SafeContract_v1_1_1_Function<'VERSION'> = async () => { return [await this.contract.VERSION()] } - async approvedHashes([owner, txHash]: readonly [string, string]): Promise<[bigint]> { - return [await this.contract.approvedHashes(owner, txHash)] + /** + * @param args - Array[owner, txHash] + * @returns Array[approvedHashes] + */ + approvedHashes: SafeContract_v1_1_1_Function<'approvedHashes'> = async (args) => { + return [await this.contract.approvedHashes(...args)] } - async domainSeparator(): Promise<[string]> { + /** + * @returns Array[domainSeparator] + */ + domainSeparator: SafeContract_v1_1_1_Function<'domainSeparator'> = async () => { return [await this.contract.domainSeparator()] } - async getModules(): Promise<[string[]]> { + /** + * Returns array of first 10 modules. + * @returns Array[Array[modules]] + */ + getModules: SafeContract_v1_1_1_Function<'getModules'> = async () => { return [await this.contract.getModules()] } - async getModulesPaginated( - args: readonly [start: string, pageSize: bigint] - ): Promise<[modules: string[], next: string]> { + /** + * Returns array of modules. + * @param args - Array[start, pageSize] + * @returns Array[Array[modules], next] + */ + getModulesPaginated: SafeContract_v1_1_1_Function<'getModulesPaginated'> = async (args) => { const res = await this.contract.getModulesPaginated(...args) return [res.array, res.next] } - async getOwners(): Promise<[string[]]> { + /** + * Returns the list of Safe owner accounts. + * @returns Array[Array[owners]] + */ + getOwners: SafeContract_v1_1_1_Function<'getOwners'> = async () => { return [await this.contract.getOwners()] } - async getThreshold(): Promise<[bigint]> { + /** + * Returns the Safe threshold. + * @returns Array[threshold] + */ + getThreshold: SafeContract_v1_1_1_Function<'getThreshold'> = async () => { return [await this.contract.getThreshold()] } - async isOwner(args: readonly [address: string]): Promise<[boolean]> { + /** + * Checks if a specific address is an owner of the current Safe. + * @param args - Array[address] + * @returns Array[isOwner] + */ + isOwner: SafeContract_v1_1_1_Function<'isOwner'> = async (args) => { return [await this.contract.isOwner(...args)] } - async nonce(): Promise<[bigint]> { + /** + * Returns the Safe nonce. + * @returns Array[nonce] + */ + nonce: SafeContract_v1_1_1_Function<'nonce'> = async () => { return [await this.contract.nonce()] } - async signedMessages(args: readonly [messageHash: string]): Promise<[bigint]> { + /** + * @param args - Array[messageHash] + * @returns Array[signedMessages] + */ + signedMessages: SafeContract_v1_1_1_Function<'signedMessages'> = async (args) => { return [await this.contract.signedMessages(...args)] } - async getMessageHash(args: readonly [message: string]): Promise<[string]> { + /** + * Returns hash of a message that can be signed by owners. + * @param args - Array[message] + * @returns Array[messageHash] + */ + getMessageHash: SafeContract_v1_1_1_Function<'getMessageHash'> = async (args) => { return [await this.contract.getMessageHash(...args)] } - async encodeTransactionData( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns the bytes that are hashed to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[encodedData] + */ + encodeTransactionData: SafeContract_v1_1_1_Function<'encodeTransactionData'> = async (args) => { return [await this.contract.encodeTransactionData(...args)] } - async getTransactionHash( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns hash to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[transactionHash] + */ + getTransactionHash: SafeContract_v1_1_1_Function<'getTransactionHash'> = async (args) => { return [await this.contract.getTransactionHash(...args)] } - encode: EncodeSafeFunction = (functionToEncode, args) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } - - estimateGas: EstimateGasSafeFunction = ( - functionToEstimate, - args, - options = {} - ) => { - return this.contract.getFunction(functionToEstimate).estimateGas(...args, options) - } - - // Custom method (not defined in the Safe Contract) + /** + * Marks a hash as approved. This can be used to validate a hash that is used by a signature. + * @param hash - The hash that should be marked as approved for signatures that are verified by this contract. + * @param options - Optional transaction options. + * @returns Transaction result. + */ async approveHash( hash: string, options?: EthersTransactionOptions @@ -170,12 +190,12 @@ class SafeContract_v1_1_1_Ethers return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) - getAddress(): Promise { - return this.contract.getAddress() - } - - // Custom method (not defined in the Safe Contract) + /** + * Executes a transaction. + * @param safeTransaction - The Safe transaction to execute. + * @param options - Transaction options. + * @returns Transaction result. + */ async execTransaction( safeTransaction: SafeTransaction, options?: EthersTransactionOptions @@ -216,7 +236,11 @@ class SafeContract_v1_1_1_Ethers return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) + /** + * Checks if a specific Safe module is enabled for the current Safe. + * @param moduleAddress - The module address to check. + * @returns True, if the module with the given address is enabled. + */ async isModuleEnabled(moduleAddress: string): Promise { const [modules] = await this.getModules() const isModuleEnabled = modules.some((enabledModuleAddress: string) => @@ -225,7 +249,12 @@ class SafeContract_v1_1_1_Ethers return isModuleEnabled } - // Custom method (not defined in the Safe Contract) + /** + * Checks whether a given Safe transaction can be executed successfully with no errors. + * @param safeTransaction - The Safe transaction to check. + * @param options - Optional transaction options. + * @returns True, if the given transactions is valid. + */ async isValidTransaction( safeTransaction: SafeTransaction, options: EthersTransactionOptions = {} diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.2.0/SafeContract_v1_2_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.2.0/SafeContract_v1_2_0_Ethers.ts index 1ea0c1f5c..40f26dbeb 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.2.0/SafeContract_v1_2_0_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.2.0/SafeContract_v1_2_0_Ethers.ts @@ -5,15 +5,12 @@ import { EthersTransactionResult } from '@safe-global/protocol-kit/adapters/ethers/types' import SafeContract_v1_2_0_Contract, { - SafeContract_v1_2_0_Abi + SafeContract_v1_2_0_Abi, + SafeContract_v1_2_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.2.0/SafeContract_v1_2_0' import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' import safe_1_2_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.2.0/gnosis_safe' import { SafeTransaction, SafeTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeSafeFunction, - EstimateGasSafeFunction -} from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' /** * SafeContract_v1_2_0_Ethers is the implementation specific to the Safe contract version 1.2.0. @@ -61,108 +58,137 @@ class SafeContract_v1_2_0_Ethers this.safeVersion = safeVersion } - async NAME(): Promise<[string]> { + /** + * @returns Array[contractName] + */ + NAME: SafeContract_v1_2_0_Function<'NAME'> = async () => { return [await this.contract.NAME()] } - async VERSION(): Promise<[string]> { + /** + * @returns Array[safeContractVersion] + */ + VERSION: SafeContract_v1_2_0_Function<'VERSION'> = async () => { return [await this.contract.VERSION()] } - async approvedHashes([owner, txHash]: readonly [string, string]): Promise<[bigint]> { - return [await this.contract.approvedHashes(owner, txHash)] + /** + * @param args - Array[owner, txHash] + * @returns Array[approvedHashes] + */ + approvedHashes: SafeContract_v1_2_0_Function<'approvedHashes'> = async (args) => { + return [await this.contract.approvedHashes(...args)] } - async domainSeparator(): Promise<[string]> { + /** + * @returns Array[domainSeparator] + */ + domainSeparator: SafeContract_v1_2_0_Function<'domainSeparator'> = async () => { return [await this.contract.domainSeparator()] } - async getModules(): Promise<[string[]]> { + /** + * Returns array of first 10 modules. + * @returns Array[Array[modules]] + */ + getModules: SafeContract_v1_2_0_Function<'getModules'> = async () => { return [await this.contract.getModules()] } - async getModulesPaginated( - args: readonly [start: string, pageSize: bigint] - ): Promise<[modules: string[], next: string]> { + /** + * Returns array of modules. + * @param args - Array[start, pageSize] + * @returns Array[Array[modules], next] + */ + getModulesPaginated: SafeContract_v1_2_0_Function<'getModulesPaginated'> = async (args) => { const res = await this.contract.getModulesPaginated(...args) return [res.array, res.next] } - async getOwners(): Promise<[string[]]> { + /** + * Returns the list of Safe owner accounts. + * @returns Array[Array[owners]] + */ + getOwners: SafeContract_v1_2_0_Function<'getOwners'> = async () => { return [await this.contract.getOwners()] } - async getThreshold(): Promise<[bigint]> { + /** + * Returns the Safe threshold. + * @returns Array[threshold] + */ + getThreshold: SafeContract_v1_2_0_Function<'getThreshold'> = async () => { return [await this.contract.getThreshold()] } - async isModuleEnabled(args: readonly [moduleAddress: string]): Promise<[boolean]> { + /** + * Checks if a specific Safe module is enabled for the current Safe. + * @param args - Array[moduleAddress] + * @returns Array[isEnabled] + */ + isModuleEnabled: SafeContract_v1_2_0_Function<'isModuleEnabled'> = async (args) => { return [await this.contract.isModuleEnabled(...args)] } - async isOwner(args: readonly [address: string]): Promise<[boolean]> { + /** + * Checks if a specific address is an owner of the current Safe. + * @param args - Array[address] + * @returns Array[isOwner] + */ + isOwner: SafeContract_v1_2_0_Function<'isOwner'> = async (args) => { return [await this.contract.isOwner(...args)] } - async nonce(): Promise<[bigint]> { + /** + * Returns the Safe nonce. + * @returns Array[nonce] + */ + nonce: SafeContract_v1_2_0_Function<'nonce'> = async () => { return [await this.contract.nonce()] } - async signedMessages(args: readonly [messageHash: string]): Promise<[bigint]> { + /** + * @param args - Array[messageHash] + * @returns Array[signedMessages] + */ + signedMessages: SafeContract_v1_2_0_Function<'signedMessages'> = async (args) => { return [await this.contract.signedMessages(...args)] } - async getMessageHash(args: readonly [message: string]): Promise<[string]> { + /** + * @param args - Array[message] + * @returns Array[messageHash] + */ + getMessageHash: SafeContract_v1_2_0_Function<'getMessageHash'> = async (args) => { return [await this.contract.getMessageHash(...args)] } - async encodeTransactionData( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Encodes the data for a transaction to the Safe contract. + * + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[encodedData] + */ + encodeTransactionData: SafeContract_v1_2_0_Function<'encodeTransactionData'> = async (args) => { return [await this.contract.encodeTransactionData(...args)] } - async getTransactionHash( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns hash to be signed by owners. + * + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[transactionHash] + */ + getTransactionHash: SafeContract_v1_2_0_Function<'getTransactionHash'> = async (args) => { return [await this.contract.getTransactionHash(...args)] } - encode: EncodeSafeFunction = (functionToEncode, args) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } - - estimateGas: EstimateGasSafeFunction = ( - functionToEstimate, - args, - options = {} - ) => { - return this.contract.getFunction(functionToEstimate).estimateGas(...args, options) - } - - // Custom method (not defined in the Safe Contract) + /** + * Marks a hash as approved. This can be used to validate a hash that is used by a signature. + * @param hash - The hash that should be marked as approved for signatures that are verified by this contract. + * @param options - Optional transaction options. + * @returns Transaction result. + */ async approveHash( hash: string, options?: EthersTransactionOptions @@ -173,7 +199,12 @@ class SafeContract_v1_2_0_Ethers return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) + /** + * Executes a transaction. + * @param safeTransaction - The Safe transaction to execute. + * @param options - Transaction options. + * @returns Transaction result. + */ async execTransaction( safeTransaction: SafeTransaction, options?: EthersTransactionOptions @@ -214,17 +245,20 @@ class SafeContract_v1_2_0_Ethers return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) - async getAddress(): Promise { - return this.contract.getAddress() - } - - // Custom method (not defined in the Safe Contract) + /** + * Returns the chain id of the Safe contract. (Custom method - not defined in the Safe Contract) + * @returns Array[chainId] + */ async getChainId(): Promise<[bigint]> { return [await this.contract.getChainId()] } - // Custom method (not defined in the Safe Contract) + /** + * Checks whether a given Safe transaction can be executed successfully with no errors. + * @param safeTransaction - The Safe transaction to check. + * @param options - Optional transaction options. + * @returns True, if the given transactions is valid. + */ async isValidTransaction( safeTransaction: SafeTransaction, options: EthersTransactionOptions = {} diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Ethers.ts index 0b4ff2975..572abe640 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Ethers.ts @@ -5,16 +5,13 @@ import { EthersTransactionResult } from '@safe-global/protocol-kit/adapters/ethers/types' import SafeContract_v1_3_0_Contract, { - SafeContract_v1_3_0_Abi + SafeContract_v1_3_0_Abi, + SafeContract_v1_3_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.3.0/SafeContract_v1_3_0' import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' import safe_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.3.0/gnosis_safe_l2' import { SENTINEL_ADDRESS } from '@safe-global/protocol-kit/adapters/ethers/utils/constants' import { SafeTransaction, SafeTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeSafeFunction, - EstimateGasSafeFunction -} from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' /** * SafeContract_v1_3_0_Ethers is the implementation specific to the Safe contract version 1.3.0. @@ -62,103 +59,142 @@ class SafeContract_v1_3_0_Ethers this.safeVersion = safeVersion } - encode: EncodeSafeFunction = (functionToEncode, args) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } - - estimateGas: EstimateGasSafeFunction = ( - functionToEstimate, - args, - options = {} - ) => { - const contractMethodToStimate = this.contract.getFunction(functionToEstimate) - - return contractMethodToStimate.estimateGas(...args, options) - } - - async VERSION(): Promise<[string]> { + /** + * @returns Array[safeContractVersion] + */ + VERSION: SafeContract_v1_3_0_Function<'VERSION'> = async () => { return [await this.contract.VERSION()] } - async approvedHashes([owner, txHash]: readonly [string, string]): Promise<[bigint]> { - return [await this.contract.approvedHashes(owner, txHash)] + /** + * @param args - Array[owner, txHash] + * @returns Array[approvedHashes] + */ + approvedHashes: SafeContract_v1_3_0_Function<'approvedHashes'> = async (args) => { + return [await this.contract.approvedHashes(...args)] } - // TODO: rename the args - async checkNSignatures(args: readonly [string, string, string, bigint]): Promise<[]> { - // this method just checks whether the signature provided is valid for the provided data and hash. Reverts otherwise. + /** + * Checks whether the signature provided is valid for the provided data, hash and number of required signatures. + * Will revert otherwise. + * @param args - Array[dataHash, data, signatures, requiredSignatures] + * @returns Empty array + */ + checkNSignatures: SafeContract_v1_3_0_Function<'checkNSignatures'> = async (args) => { await this.contract.checkNSignatures(...args) return [] } - // TODO: rename the args - async checkSignatures(args: readonly [string, string, string]): Promise<[]> { + /** + * Checks whether the signature provided is valid for the provided data and hash. Will revert otherwise. + * @param args - Array[dataHash, data, signatures] + * @returns Empty array + */ + checkSignatures: SafeContract_v1_3_0_Function<'checkSignatures'> = async (args) => { await this.contract.checkSignatures(...args) return [] } - async domainSeparator(): Promise<[string]> { + /** + * @returns Array[domainSeparator] + */ + domainSeparator: SafeContract_v1_3_0_Function<'domainSeparator'> = async () => { return [await this.contract.domainSeparator()] } - // TODO: rename the args - async encodeTransactionData( - args: readonly [string, bigint, string, number, bigint, bigint, bigint, string, string, bigint] - ): Promise<[string]> { + /** + * Encodes the data for a transaction to the Safe contract. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[encodedData] + */ + encodeTransactionData: SafeContract_v1_3_0_Function<'encodeTransactionData'> = async (args) => { return [await this.contract.encodeTransactionData(...args)] } - async getChainId(): Promise<[bigint]> { - return [await this.contract.getChainId()] - } - - async getModulesPaginated( - args: readonly [start: string, pageSize: bigint] - ): Promise<[modules: string[], next: string]> { + /** + * Returns array of modules. + * @param args - Array[start, pageSize] + * @returns Array[Array[modules], next] + */ + getModulesPaginated: SafeContract_v1_3_0_Function<'getModulesPaginated'> = async (args) => { const res = await this.contract.getModulesPaginated(...args) return [res.array, res.next] } - async getOwners(): Promise { + /** + * Returns the list of Safe owner accounts. + * @returns Array[Array[owners]] + */ + getOwners: SafeContract_v1_3_0_Function<'getOwners'> = async () => { return [await this.contract.getOwners()] } - // TODO: rename the args - async getStorageAt(args: readonly [bigint, bigint]): Promise<[string]> { + /** + * Reads `length` bytes of storage in the currents contract + * @param args - Array[offset, length] + * @returns Array[storage] + */ + getStorageAt: SafeContract_v1_3_0_Function<'getStorageAt'> = async (args) => { return [await this.contract.getStorageAt(...args)] } - async getThreshold(): Promise<[bigint]> { + /** + * Returns the Safe threshold. + * @returns Array[threshold] + */ + getThreshold: SafeContract_v1_3_0_Function<'getThreshold'> = async () => { return [await this.contract.getThreshold()] } - // TODO: rename the args - async getTransactionHash( - args: readonly [string, bigint, string, number, bigint, bigint, bigint, string, string, bigint] - ): Promise<[string]> { + /** + * Returns hash to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[transactionHash] + */ + getTransactionHash: SafeContract_v1_3_0_Function<'getTransactionHash'> = async (args) => { return [await this.contract.getTransactionHash(...args)] } - // TODO: rename the args - async isModuleEnabled(args: readonly [string]): Promise<[boolean]> { + /** + * Checks if a specific Safe module is enabled for the current Safe. + * @param args - Array[moduleAddress] + * @returns Array[isEnabled] + */ + isModuleEnabled: SafeContract_v1_3_0_Function<'isModuleEnabled'> = async (args) => { return [await this.contract.isModuleEnabled(...args)] } - // TODO: rename the args - async isOwner(args: readonly [string]): Promise<[boolean]> { + /** + * Checks if a specific address is an owner of the current Safe. + * @param args - Array[address] + * @returns Array[isOwner] + */ + isOwner: SafeContract_v1_3_0_Function<'isOwner'> = async (args) => { return [await this.contract.isOwner(...args)] } - async nonce(): Promise<[bigint]> { + /** + * Returns the Safe nonce. + * @returns Array[nonce] + */ + nonce: SafeContract_v1_3_0_Function<'nonce'> = async () => { return [await this.contract.nonce()] } - // TODO: rename the args - async signedMessages(args: readonly [string]): Promise<[bigint]> { + /** + * @param args - Array[messageHash] + * @returns Array[signedMessages] + */ + signedMessages: SafeContract_v1_3_0_Function<'signedMessages'> = async (args) => { return [await this.contract.signedMessages(...args)] } - // custom methods (not defined in the Safe Contract) + /** + * Checks whether a given Safe transaction can be executed successfully with no errors. + * @param safeTransaction - The Safe transaction to check. + * @param options - Optional transaction options. + * @returns True, if the given transactions is valid. + */ async isValidTransaction( safeTransaction: SafeTransaction, options: EthersTransactionOptions = {} @@ -201,6 +237,12 @@ class SafeContract_v1_3_0_Ethers } } + /** + * Executes a transaction. + * @param safeTransaction - The Safe transaction to execute. + * @param options - Transaction options. + * @returns Transaction result. + */ async execTransaction( safeTransaction: SafeTransaction, options?: EthersTransactionOptions @@ -241,11 +283,21 @@ class SafeContract_v1_3_0_Ethers return toTxResult(txResponse, options) } - async getModules(): Promise { + /** + * Returns array of first 10 modules. + * @returns Array[modules] + */ + async getModules(): Promise { const [modules] = await this.getModulesPaginated([SENTINEL_ADDRESS, BigInt(10)]) return modules } + /** + * Marks a hash as approved. This can be used to validate a hash that is used by a signature. + * @param hash - The hash that should be marked as approved for signatures that are verified by this contract. + * @param options - Optional transaction options. + * @returns Transaction result. + */ async approveHash( hash: string, options?: EthersTransactionOptions @@ -256,8 +308,12 @@ class SafeContract_v1_3_0_Ethers return toTxResult(txResponse, options) } - getAddress(): Promise { - return this.contract.getAddress() + /** + * Returns the chain id of the Safe contract. (Custom method - not defined in the Safe Contract) + * @returns Array[chainId] + */ + async getChainId(): Promise<[bigint]> { + return [await this.contract.getChainId()] } // TODO: Remove this mapper after remove Typechain diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Ethers.ts index a2e60a657..0261bd6ae 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Ethers.ts @@ -5,16 +5,13 @@ import { EthersTransactionResult } from '@safe-global/protocol-kit/adapters/ethers/types' import SafeContract_v1_4_1_Contract, { - SafeContract_v1_4_1_Abi + SafeContract_v1_4_1_Abi, + SafeContract_v1_4_1_Function } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.4.1/SafeContract_v1_4_1' import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' import safe_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.4.1/safe_l2' import { SENTINEL_ADDRESS } from '@safe-global/protocol-kit/adapters/ethers/utils/constants' import { SafeTransaction, SafeTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeSafeFunction, - EstimateGasSafeFunction -} from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' /** * SafeContract_v1_4_1_Ethers is the implementation specific to the Safe contract version 1.4.1. @@ -62,130 +59,190 @@ class SafeContract_v1_4_1_Ethers this.safeVersion = safeVersion } - async VERSION(): Promise<[string]> { + /** + * @returns Array[safeContractVersion] + */ + VERSION: SafeContract_v1_4_1_Function<'VERSION'> = async () => { return [await this.contract.VERSION()] } - async approvedHashes([owner, txHash]: readonly [string, string]): Promise<[bigint]> { - return [await this.contract.approvedHashes(owner, txHash)] + /** + * @param args - Array[owner, txHash] + * @returns Array[approvedHashes] + */ + approvedHashes: SafeContract_v1_4_1_Function<'approvedHashes'> = async (args) => { + return [await this.contract.approvedHashes(...args)] } - async checkNSignatures( - args: readonly [dataHash: string, data: string, signatures: string, requiredSignatures: bigint] - ): Promise<[]> { - // this method just checks whether the signature provided is valid for the provided data and hash. Reverts otherwise. + /** + * Checks whether the signature provided is valid for the provided data, hash and number of required signatures. + * Will revert otherwise. + * @param args - Array[dataHash, data, signatures, requiredSignatures] + * @returns Empty array + */ + checkNSignatures: SafeContract_v1_4_1_Function<'checkNSignatures'> = async (args) => { await this.contract.checkNSignatures(...args) return [] } - async checkSignatures( - args: readonly [dataHash: string, data: string, signatures: string] - ): Promise<[]> { + /** + * Checks whether the signature provided is valid for the provided data and hash. Will revert otherwise. + * @param args - Array[dataHash, data, signatures] + * @returns Empty array + */ + checkSignatures: SafeContract_v1_4_1_Function<'checkSignatures'> = async (args) => { await this.contract.checkSignatures(...args) return [] } - async domainSeparator(): Promise<[string]> { + /** + * @returns Array[domainSeparator] + */ + domainSeparator: SafeContract_v1_4_1_Function<'domainSeparator'> = async () => { return [await this.contract.domainSeparator()] } - async encodeTransactionData( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Encodes the data for a transaction to the Safe contract. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[encodedData] + */ + encodeTransactionData: SafeContract_v1_4_1_Function<'encodeTransactionData'> = async (args) => { return [await this.contract.encodeTransactionData(...args)] } - async getChainId(): Promise<[bigint]> { - return [await this.contract.getChainId()] - } - - async getModulesPaginated( - args: readonly [start: string, pageSize: bigint] - ): Promise<[modules: string[], next: string]> { + /** + * Returns array of modules. + * @param args - Array[start, pageSize] + * @returns Array[Array[modules], next] + */ + getModulesPaginated: SafeContract_v1_4_1_Function<'getModulesPaginated'> = async (args) => { const res = await this.contract.getModulesPaginated(...args) return [res.array, res.next] } - async getOwners(): Promise { + /** + * Returns the list of Safe owner accounts. + * @returns Array[Array[owners]] + */ + getOwners: SafeContract_v1_4_1_Function<'getOwners'> = async () => { return [await this.contract.getOwners()] } - async getStorageAt(args: readonly [offset: bigint, length: bigint]): Promise<[string]> { + /** + * Reads `length` bytes of storage in the currents contract + * @param args - Array[offset, length] + * @returns Array[storage] + */ + getStorageAt: SafeContract_v1_4_1_Function<'getStorageAt'> = async (args) => { return [await this.contract.getStorageAt(...args)] } - async getThreshold(): Promise<[bigint]> { + /** + * Returns the Safe threshold. + * @returns Array[threshold] + */ + getThreshold: SafeContract_v1_4_1_Function<'getThreshold'> = async () => { return [await this.contract.getThreshold()] } - async getTransactionHash( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns hash to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[transactionHash] + */ + getTransactionHash: SafeContract_v1_4_1_Function<'getTransactionHash'> = async (args) => { return [await this.contract.getTransactionHash(...args)] } - async isModuleEnabled(args: readonly [moduleAddress: string]): Promise<[boolean]> { + /** + * Checks if a specific Safe module is enabled for the current Safe. + * @param args - Array[moduleAddress] + * @returns Array[isEnabled] + */ + isModuleEnabled: SafeContract_v1_4_1_Function<'isModuleEnabled'> = async (args) => { return [await this.contract.isModuleEnabled(...args)] } - async isOwner(args: readonly [address: string]): Promise<[boolean]> { + /** + * Checks if a specific address is an owner of the current Safe. + * @param args - Array[address] + * @returns Array[isOwner] + */ + isOwner: SafeContract_v1_4_1_Function<'isOwner'> = async (args) => { return [await this.contract.isOwner(...args)] } - async nonce(): Promise<[bigint]> { + /** + * Returns the Safe nonce. + * @returns Array[nonce] + */ + nonce: SafeContract_v1_4_1_Function<'nonce'> = async () => { return [await this.contract.nonce()] } - async signedMessages(args: readonly [messageHash: string]): Promise<[bigint]> { + /** + * @param args - Array[messageHash] + * @returns Array[signedMessages] + */ + signedMessages: SafeContract_v1_4_1_Function<'signedMessages'> = async (args) => { return [await this.contract.signedMessages(...args)] } - encode: EncodeSafeFunction = (functionToEncode, args) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } - - estimateGas: EstimateGasSafeFunction = ( - functionToEstimate, - args, - options = {} - ) => { - return this.contract.getFunction(functionToEstimate).estimateGas(...args, options) - } - - // Custom method (not defined in the Safe Contract) - async approveHash( - hash: string, - options?: EthersTransactionOptions - ): Promise { - const gasLimit = options?.gasLimit || (await this.estimateGas('approveHash', [hash], options)) - const txResponse = await this.contract.approveHash(hash, { ...options, gasLimit }) + /** + * Checks whether a given Safe transaction can be executed successfully with no errors. + * @param safeTransaction - The Safe transaction to check. + * @param options - Optional transaction options. + * @returns True, if the given transactions is valid. + */ + async isValidTransaction( + safeTransaction: SafeTransaction, + options: EthersTransactionOptions = {} + ) { + try { + const gasLimit = + options?.gasLimit || + (await this.estimateGas( + 'execTransaction', + [ + safeTransaction.data.to, + BigInt(safeTransaction.data.value), + safeTransaction.data.data, + safeTransaction.data.operation, + BigInt(safeTransaction.data.safeTxGas), + BigInt(safeTransaction.data.baseGas), + BigInt(safeTransaction.data.gasPrice), + safeTransaction.data.gasToken, + safeTransaction.data.refundReceiver, + safeTransaction.encodedSignatures() + ], + options + )) - return toTxResult(txResponse, options) + return await this.contract.execTransaction.staticCall( + safeTransaction.data.to, + BigInt(safeTransaction.data.value), + safeTransaction.data.data, + safeTransaction.data.operation, + BigInt(safeTransaction.data.safeTxGas), + BigInt(safeTransaction.data.baseGas), + BigInt(safeTransaction.data.gasPrice), + safeTransaction.data.gasToken, + safeTransaction.data.refundReceiver, + safeTransaction.encodedSignatures(), + { ...options, gasLimit } + ) + } catch (error) { + return false + } } - // Custom method (not defined in the Safe Contract) + /** + * Executes a transaction. + * @param safeTransaction - The Safe transaction to execute. + * @param options - Transaction options. + * @returns Transaction result. + */ async execTransaction( safeTransaction: SafeTransaction, options?: EthersTransactionOptions @@ -226,58 +283,37 @@ class SafeContract_v1_4_1_Ethers return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) - getAddress(): Promise { - return this.contract.getAddress() - } - - // Custom method (not defined in the Safe Contract) - async getModules(): Promise { + /** + * Returns array of first 10 modules. + * @returns Array[modules] + */ + async getModules(): Promise { const [modules] = await this.getModulesPaginated([SENTINEL_ADDRESS, BigInt(10)]) return modules } - // Custom method (not defined in the Safe Contract) - async isValidTransaction( - safeTransaction: SafeTransaction, - options: EthersTransactionOptions = {} - ) { - try { - const gasLimit = - options?.gasLimit || - (await this.estimateGas( - 'execTransaction', - [ - safeTransaction.data.to, - BigInt(safeTransaction.data.value), - safeTransaction.data.data, - safeTransaction.data.operation, - BigInt(safeTransaction.data.safeTxGas), - BigInt(safeTransaction.data.baseGas), - BigInt(safeTransaction.data.gasPrice), - safeTransaction.data.gasToken, - safeTransaction.data.refundReceiver, - safeTransaction.encodedSignatures() - ], - options - )) + /** + * Marks a hash as approved. This can be used to validate a hash that is used by a signature. + * @param hash - The hash that should be marked as approved for signatures that are verified by this contract. + * @param options - Optional transaction options. + * @returns Transaction result. + */ + async approveHash( + hash: string, + options?: EthersTransactionOptions + ): Promise { + const gasLimit = options?.gasLimit || (await this.estimateGas('approveHash', [hash], options)) + const txResponse = await this.contract.approveHash(hash, { ...options, gasLimit }) - return await this.contract.execTransaction.staticCall( - safeTransaction.data.to, - BigInt(safeTransaction.data.value), - safeTransaction.data.data, - safeTransaction.data.operation, - BigInt(safeTransaction.data.safeTxGas), - BigInt(safeTransaction.data.baseGas), - BigInt(safeTransaction.data.gasPrice), - safeTransaction.data.gasToken, - safeTransaction.data.refundReceiver, - safeTransaction.encodedSignatures(), - { ...options, gasLimit } - ) - } catch (error) { - return false - } + return toTxResult(txResponse, options) + } + + /** + * Returns the chain id of the Safe contract. (Custom method - not defined in the Safe Contract) + * @returns Array[chainId] + */ + async getChainId(): Promise<[bigint]> { + return [await this.contract.getChainId()] } // TODO: Remove this mapper after remove Typechain diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers.ts index 33bc1bb8e..453dc3b98 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers.ts @@ -1,19 +1,27 @@ -import { Contract, ContractRunner, InterfaceAbi } from 'ethers' +import { Abi } from 'abitype' +import { ContractRunner, InterfaceAbi } from 'ethers' +import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers/types' 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' +import BaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/BaseContractEthers' +import { + CreateProxyProps as CreateProxyPropsGeneral, + SafeVersion +} from '@safe-global/safe-core-sdk-types' +import { contractName } from '@safe-global/protocol-kit/contracts/config' + +export interface CreateProxyProps extends CreateProxyPropsGeneral { + options?: EthersTransactionOptions +} /** - * Abstract class SafeProxyFactoryBaseContractEthers extends SafeProxyFactoryBaseContract to specifically integrate with the Ethers.js v6 library. + * Abstract class SafeProxyFactoryBaseContractEthers extends BaseContractEthers to specifically integrate with the SafeProxyFactory contract. * 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. + * @extends BaseContractEthers - Extends the generic BaseContractEthers. * * Example subclasses: * - SafeProxyFactoryContract_v1_4_1_Ethers extends SafeProxyFactoryBaseContractEthers @@ -23,10 +31,9 @@ import { SafeVersion } from '@safe-global/safe-core-sdk-types' * - SafeProxyFactoryContract_v1_0_0_Ethers extends SafeProxyFactoryBaseContractEthers */ abstract class SafeProxyFactoryBaseContractEthers< - SafeProxyFactoryContractAbiType extends InterfaceAbi -> extends SafeProxyFactoryBaseContract { - contract: Contract - adapter: EthersAdapter + SafeProxyFactoryContractAbiType extends InterfaceAbi & Abi +> extends BaseContractEthers { + contractName: contractName /** * @constructor @@ -48,14 +55,20 @@ abstract class SafeProxyFactoryBaseContractEthers< customContractAbi?: SafeProxyFactoryContractAbiType, runner?: ContractRunner | null ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'safeProxyFactoryVersion' - this.adapter = ethersAdapter - this.contract = new Contract( - this.contractAddress, - this.contractAbi, - runner || this.adapter.getSigner() + super( + contractName, + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi, + runner ) + + this.contractName = contractName } } 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 index 5cbcefc1c..4c06716d6 100644 --- 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 @@ -1,14 +1,12 @@ import { ContractRunner, EventLog } from 'ethers' -import SafeProxyFactoryBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers' +import SafeProxyFactoryBaseContractEthers, { + CreateProxyProps +} 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 + SafeProxyFactoryContract_v1_0_0_Abi, + SafeProxyFactoryContract_v1_0_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0' import { SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -57,57 +55,54 @@ class SafeProxyFactoryContract_v1_0_0_Ethers 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]> { + /** + * Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address. + * @returns Array[creationCode] + */ + proxyCreationCode: SafeProxyFactoryContract_v1_0_0_Function<'proxyCreationCode'> = async () => { return [await this.contract.proxyCreationCode()] } - async proxyRuntimeCode(): Promise<[string]> { + /** + * Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed. + * @returns Array[runtimeCode] + */ + proxyRuntimeCode: SafeProxyFactoryContract_v1_0_0_Function<'proxyRuntimeCode'> = async () => { return [await this.contract.proxyRuntimeCode()] } - async createProxy(args: readonly [masterCopy: string, data: string]): Promise<[string]> { + /** + * Allows to create new proxy contact and execute a message call to the new proxy within one transaction. + * @param args - Array[masterCopy, data] + * @returns Array[proxyAddress] + */ + createProxy: SafeProxyFactoryContract_v1_0_0_Function<'createProxy'> = async (args) => { return [await this.contract.createProxy(...args)] } - async createProxyWithNonce( - args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param args - Array[masterCopy, initializer, saltNonce] + * @returns Array[proxyAddress] + */ + createProxyWithNonce: SafeProxyFactoryContract_v1_0_0_Function<'createProxyWithNonce'> = async ( + args + ) => { return [await this.contract.createProxyWithNonce(...args)] } + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param {CreateProxyProps} props - Properties for the new proxy contract. + * @returns The address of the new proxy contract. + */ async createProxyWithOptions({ safeSingletonAddress, initializer, saltNonce, options, callback - }: { - safeSingletonAddress: string - initializer: string - saltNonce: string - options?: EthersTransactionOptions - callback?: (txHash: string) => void - }): Promise { + }: CreateProxyProps): Promise { const saltNonceBigInt = BigInt(saltNonce) if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') 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 index fc5c70e02..4db36497f 100644 --- 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 @@ -1,14 +1,12 @@ import { ContractRunner, EventLog } from 'ethers' -import SafeProxyFactoryBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers' +import SafeProxyFactoryBaseContractEthers, { + CreateProxyProps +} 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 + SafeProxyFactoryContract_v1_1_1_Abi, + SafeProxyFactoryContract_v1_1_1_Function } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1' import { SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -57,69 +55,74 @@ class SafeProxyFactoryContract_v1_1_1_Ethers 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]> { + /** + * Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address. + * @returns Array[creationCode] + */ + proxyCreationCode: SafeProxyFactoryContract_v1_1_1_Function<'proxyCreationCode'> = async () => { return [await this.contract.proxyCreationCode()] } - async proxyRuntimeCode(): Promise<[string]> { + /** + * Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed. + * @returns Array[runtimeCode] + */ + proxyRuntimeCode: SafeProxyFactoryContract_v1_1_1_Function<'proxyRuntimeCode'> = async () => { return [await this.contract.proxyRuntimeCode()] } - async calculateCreateProxyWithNonceAddress( - args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { - return [await this.contract.calculateCreateProxyWithNonceAddress(...args)] - } + /** + * Allows to get the address for a new proxy contact created via `createProxyWithNonce`. + * @param args - Array[masterCopy, initializer, saltNonce] + * @returns Array[proxyAddress] + */ + calculateCreateProxyWithNonceAddress: SafeProxyFactoryContract_v1_1_1_Function<'calculateCreateProxyWithNonceAddress'> = + async (args) => { + return [await this.contract.calculateCreateProxyWithNonceAddress(...args)] + } - async createProxy(args: readonly [masterCopy: string, data: string]): Promise<[string]> { + /** + * Allows to create new proxy contact and execute a message call to the new proxy within one transaction. + * @param args - Array[masterCopy, data] + * @returns Array[proxyAddress] + */ + createProxy: SafeProxyFactoryContract_v1_1_1_Function<'createProxy'> = async (args) => { 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)] - } + /** + * Allows to create new proxy contract, execute a message call to the new proxy and call a specified callback within one transaction. + * @param args - Array[masterCopy, initializer, saltNonce, callback] + * @returns Array[proxyAddress] + */ + createProxyWithCallback: SafeProxyFactoryContract_v1_1_1_Function<'createProxyWithCallback'> = + async (args) => { + return [await this.contract.createProxyWithCallback(...args)] + } - async createProxyWithNonce( - args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param args - Array[masterCopy, initializer, saltNonce] + * @returns Array[proxyAddress] + */ + createProxyWithNonce: SafeProxyFactoryContract_v1_1_1_Function<'createProxyWithNonce'> = async ( + args + ) => { return [await this.contract.createProxyWithNonce(...args)] } + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param {CreateProxyProps} props - Properties for the new proxy contract. + * @returns The address of the new proxy contract. + */ async createProxyWithOptions({ safeSingletonAddress, initializer, saltNonce, options, callback - }: { - safeSingletonAddress: string - initializer: string - saltNonce: string - options?: EthersTransactionOptions - callback?: (txHash: string) => void - }): Promise { + }: CreateProxyProps): Promise { const saltNonceBigInt = BigInt(saltNonce) if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') 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 index b2d516176..38f2d32e3 100644 --- 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 @@ -1,14 +1,12 @@ import { ContractRunner, EventLog } from 'ethers' -import SafeProxyFactoryBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers' +import SafeProxyFactoryBaseContractEthers, { + CreateProxyProps +} 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 + SafeProxyFactoryContract_v1_3_0_Abi, + SafeProxyFactoryContract_v1_3_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0' import { SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -57,69 +55,74 @@ class SafeProxyFactoryContract_v1_3_0_Ethers 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]> { + /** + * Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address. + * @returns Array[creationCode] + */ + proxyCreationCode: SafeProxyFactoryContract_v1_3_0_Function<'proxyCreationCode'> = async () => { return [await this.contract.proxyCreationCode()] } - async proxyRuntimeCode(): Promise<[string]> { + /** + * Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed. + * @returns Array[runtimeCode] + */ + proxyRuntimeCode: SafeProxyFactoryContract_v1_3_0_Function<'proxyRuntimeCode'> = async () => { return [await this.contract.proxyRuntimeCode()] } - async calculateCreateProxyWithNonceAddress( - args: readonly [singleton: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { - return [await this.contract.calculateCreateProxyWithNonceAddress(...args)] - } + /** + * Allows to get the address for a new proxy contact created via `createProxyWithNonce`. + * @param args - Array[singleton, initializer, saltNonce] + * @returns Array[proxyAddress] + */ + calculateCreateProxyWithNonceAddress: SafeProxyFactoryContract_v1_3_0_Function<'calculateCreateProxyWithNonceAddress'> = + async (args) => { + return [await this.contract.calculateCreateProxyWithNonceAddress(...args)] + } - async createProxy(args: readonly [singleton: string, data: string]): Promise<[string]> { + /** + * Allows to create new proxy contact and execute a message call to the new proxy within one transaction. + * @param args - Array[singleton, data] + * @returns Array[proxyAddress] + */ + createProxy: SafeProxyFactoryContract_v1_3_0_Function<'createProxy'> = async (args) => { 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)] - } + /** + * Allows to create new proxy contract, execute a message call to the new proxy and call a specified callback within one transaction. + * @param args - Array[singleton, initializer, saltNonce, callback] + * @returns Array[proxyAddress] + */ + createProxyWithCallback: SafeProxyFactoryContract_v1_3_0_Function<'createProxyWithCallback'> = + async (args) => { + return [await this.contract.createProxyWithCallback(...args)] + } - async createProxyWithNonce( - args: readonly [singleton: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param args - Array[singleton, initializer, saltNonce] + * @returns Array[proxyAddress] + */ + createProxyWithNonce: SafeProxyFactoryContract_v1_3_0_Function<'createProxyWithNonce'> = async ( + args + ) => { return [await this.contract.createProxyWithNonce(...args)] } + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param {CreateProxyProps} props - Properties for the new proxy contract. + * @returns The address of the new proxy contract. + */ async createProxyWithOptions({ safeSingletonAddress, initializer, saltNonce, options, callback - }: { - safeSingletonAddress: string - initializer: string - saltNonce: string - options?: EthersTransactionOptions - callback?: (txHash: string) => void - }): Promise { + }: CreateProxyProps): Promise { const saltNonceBigInt = BigInt(saltNonce) if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') 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 index bf9ff98fe..a54af4615 100644 --- 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 @@ -1,14 +1,12 @@ import { ContractRunner, EventLog } from 'ethers' -import SafeProxyFactoryBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractEthers' +import SafeProxyFactoryBaseContractEthers, { + CreateProxyProps +} 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 + SafeProxyFactoryContract_v1_4_1_Abi, + SafeProxyFactoryContract_v1_4_1_Function } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1' import { SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -57,65 +55,66 @@ class SafeProxyFactoryContract_v1_4_1_Ethers 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]> { + /** + * Returns the ID of the chain the contract is currently deployed on. + * @returns Array[chainId] + */ + getChainId: SafeProxyFactoryContract_v1_4_1_Function<'getChainId'> = async () => { return [await this.contract.getChainId()] } - async proxyCreationCode(): Promise<[string]> { + /** + * Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address. + * @returns Array[creationCode] + */ + proxyCreationCode: SafeProxyFactoryContract_v1_4_1_Function<'proxyCreationCode'> = async () => { return [await this.contract.proxyCreationCode()] } - async createChainSpecificProxyWithNonce( - args: readonly [singleton: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { - return [await this.contract.createChainSpecificProxyWithNonce(...args)] - } + /** + * Deploys a new chain-specific proxy with singleton and salt. Optionally executes an initializer call to a new proxy. + * @param args - Array[singleton, initializer, saltNonce] + * @returns Array[proxy] + */ + createChainSpecificProxyWithNonce: SafeProxyFactoryContract_v1_4_1_Function<'createChainSpecificProxyWithNonce'> = + async (args) => { + 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)] - } + /** + * Deploy a new proxy with singleton and salt. + * Optionally executes an initializer call to a new proxy and calls a specified callback address. + * @param args - Array[singleton, initializer, saltNonce, callback] + * @returns Array[proxy] + */ + createProxyWithCallback: SafeProxyFactoryContract_v1_4_1_Function<'createProxyWithCallback'> = + async (args) => { + return [await this.contract.createProxyWithCallback(...args)] + } - async createProxyWithNonce( - args: readonly [singleton: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { + /** + * Deploys a new proxy with singleton and salt. Optionally executes an initializer call to a new proxy. + * @param args - Array[singleton, initializer, saltNonce] + * @returns Array[proxy] + */ + createProxyWithNonce: SafeProxyFactoryContract_v1_4_1_Function<'createProxyWithNonce'> = async ( + args + ) => { return [await this.contract.createProxyWithNonce(...args)] } + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param {CreateProxyProps} props - Properties for the new proxy contract. + * @returns The address of the new proxy contract. + */ async createProxy({ safeSingletonAddress, initializer, saltNonce, options, callback - }: { - safeSingletonAddress: string - initializer: string - saltNonce: string - options?: EthersTransactionOptions - callback?: (txHash: string) => void - }): Promise { + }: CreateProxyProps): Promise { const saltNonceBigInt = BigInt(saltNonce) if (saltNonceBigInt < 0) throw new Error('saltNonce must be greater than or equal to 0') diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/SignMessageLibBaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/SignMessageLibBaseContractEthers.ts index bb530db96..5c17e91da 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/SignMessageLibBaseContractEthers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/SignMessageLibBaseContractEthers.ts @@ -1,29 +1,28 @@ -import { Contract, InterfaceAbi } from 'ethers' +import { Abi } from 'abitype' +import { InterfaceAbi } from 'ethers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import SignMessageLibBaseContract from '@safe-global/protocol-kit/adapters/SignMessageLibBaseContract' +import BaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/BaseContractEthers' +import { contractName } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class SignMessageLibBaseContractEthers extends SignMessageLibBaseContract to specifically integrate with the Ethers.js v6 library. + * Abstract class SignMessageLibBaseContractEthers extends BaseContractEthers to specifically integrate with the SignMessageLib contract. * It is designed to be instantiated for different versions of the SignMessageLib contract. * - * This abstract class sets up the Ethers v6 Contract object that interacts with a SignMessageLib contract version. - * * Subclasses of SignMessageLibBaseContractEthers are expected to represent specific versions of the SignMessageLib contract. * * @template SignMessageLibContractAbiType - The ABI type specific to the version of the SignMessageLib contract, extending InterfaceAbi from Ethers. - * @extends SignMessageLibBaseContract - Extends the generic SignMessageLibBaseContract with Ethers-specific implementation. + * @extends BaseContractEthers - Extends the generic BaseContractEthers. * * Example subclasses: * - SignMessageLibContract_v1_4_1_Ethers extends SignMessageLibBaseContractEthers * - SignMessageLibContract_v1_3_0_Ethers extends SignMessageLibBaseContractEthers */ abstract class SignMessageLibBaseContractEthers< - SignMessageLibContractAbiType extends InterfaceAbi -> extends SignMessageLibBaseContract { - contract: Contract - adapter: EthersAdapter + SignMessageLibContractAbiType extends InterfaceAbi & Abi +> extends BaseContractEthers { + contractName: contractName /** * @constructor @@ -44,10 +43,19 @@ abstract class SignMessageLibBaseContractEthers< customContractAddress?: string, customContractAbi?: SignMessageLibContractAbiType ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'signMessageLibVersion' + + super( + contractName, + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi + ) - this.adapter = ethersAdapter - this.contract = new Contract(this.contractAddress, this.contractAbi, this.adapter.getSigner()) + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Ethers.ts index fb1c6e692..957cd587c 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Ethers.ts @@ -3,16 +3,12 @@ import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' import SignMessageLibBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SignMessageLib/SignMessageLibBaseContractEthers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' import SignMessageLibContract_v1_3_0_Contract, { - SignMessageLibContract_v1_3_0_Abi + SignMessageLibContract_v1_3_0_Abi, + SignMessageLibContract_v1_3_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/v1.3.0/SignMessageLibContract_v1_3_0' import multisend_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SignMessageLib/v1.3.0/sign_message_lib' import { SafeVersion, SignMessageLibContract } from '@safe-global/safe-core-sdk-types' -import { - EncodeSignMessageLibFunction, - EstimateGasSignMessageLibFunction, - GetAddressSignMessageLibFunction, - SignMessageFunction -} from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/SignMessageLibBaseContract' +import { AdapterSpecificContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' /** * SignMessageLibContract_v1_3_0_Ethers is the implementation specific to the SignMessageLib contract version 1.3.0. @@ -24,7 +20,7 @@ import { */ class SignMessageLibContract_v1_3_0_Ethers extends SignMessageLibBaseContractEthers - implements SignMessageLibContract_v1_3_0_Contract + implements SignMessageLibContract_v1_3_0_Contract { safeVersion: SafeVersion @@ -50,41 +46,30 @@ class SignMessageLibContract_v1_3_0_Ethers this.safeVersion = safeVersion } - encode: EncodeSignMessageLibFunction = ( - functionToEncode, - args - ) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) + /** + * @param args - Array[message] + */ + getMessageHash: SignMessageLibContract_v1_3_0_Function<'getMessageHash'> = async (args) => { + return [await this.contract.getMessageHash(...args)] } - estimateGas: EstimateGasSignMessageLibFunction< + /** + * @param args - Array[data] + */ + signMessage: AdapterSpecificContractFunction< SignMessageLibContract_v1_3_0_Abi, - EthersTransactionOptions - > = (functionToEstimate, args, options = {}) => { - const contractMethodToEstimate = this.contract.getFunction(functionToEstimate) + EthersAdapter, + 'signMessage' + > = async (data, options) => { + if (options && !options.gasLimit) { + options.gasLimit = Number(await this.estimateGas('signMessage', data, { ...options })) + } - return contractMethodToEstimate.estimateGas(...args, options) - } + const txResponse = await this.contract.signMessage(data, { ...options }) - getAddress: GetAddressSignMessageLibFunction = () => { - return this.contract.getAddress() + return toTxResult(txResponse, options) } - async getMessageHash(args: readonly [string]): Promise { - return [await this.contract.getMessageHash(...args)] - } - - signMessage: SignMessageFunction = - async (data, options) => { - if (options && !options.gasLimit) { - options.gasLimit = Number(await this.estimateGas('signMessage', data, { ...options })) - } - - const txResponse = await this.contract.signMessage(data, { ...options }) - - return toTxResult(txResponse, options) - } - // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): SignMessageLibContract { return { diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Ethers.ts index 8ced10de5..2c0312cee 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Ethers.ts @@ -3,16 +3,12 @@ import { toTxResult } from '@safe-global/protocol-kit/adapters/ethers/utils' import SignMessageLibBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SignMessageLib/SignMessageLibBaseContractEthers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' import SignMessageLibContract_v1_4_1_Contract, { - SignMessageLibContract_v1_4_1_Abi + SignMessageLibContract_v1_4_1_Abi, + SignMessageLibContract_v1_4_1_Function } from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/v1.4.1/SignMessageLibContract_v1_4_1' import multisend_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SignMessageLib/v1.4.1/sign_message_lib' import { SafeVersion, SignMessageLibContract } from '@safe-global/safe-core-sdk-types' -import { - EncodeSignMessageLibFunction, - EstimateGasSignMessageLibFunction, - GetAddressSignMessageLibFunction, - SignMessageFunction -} from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/SignMessageLibBaseContract' +import { AdapterSpecificContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' /** * SignMessageLibContract_v1_4_1_Ethers is the implementation specific to the SignMessageLib contract version 1.4.1. @@ -24,7 +20,7 @@ import { */ class SignMessageLibContract_v1_4_1_Ethers extends SignMessageLibBaseContractEthers - implements SignMessageLibContract_v1_4_1_Contract + implements SignMessageLibContract_v1_4_1_Contract { safeVersion: SafeVersion @@ -50,41 +46,30 @@ class SignMessageLibContract_v1_4_1_Ethers this.safeVersion = safeVersion } - encode: EncodeSignMessageLibFunction = ( - functionToEncode, - args - ) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) + /** + * @param args - Array[message] + */ + getMessageHash: SignMessageLibContract_v1_4_1_Function<'getMessageHash'> = async (args) => { + return [await this.contract.getMessageHash(...args)] } - estimateGas: EstimateGasSignMessageLibFunction< + /** + * @param args - Array[data] + */ + signMessage: AdapterSpecificContractFunction< SignMessageLibContract_v1_4_1_Abi, - EthersTransactionOptions - > = (functionToEstimate, args, options = {}) => { - const contractMethodToEstimate = this.contract.getFunction(functionToEstimate) + EthersAdapter, + 'signMessage' + > = async (data, options) => { + if (options && !options.gasLimit) { + options.gasLimit = Number(await this.estimateGas('signMessage', data, { ...options })) + } - return contractMethodToEstimate.estimateGas(...args, options) - } + const txResponse = await this.contract.signMessage(data, { ...options }) - getAddress: GetAddressSignMessageLibFunction = () => { - return this.contract.getAddress() + return toTxResult(txResponse, options) } - async getMessageHash(args: readonly [string]): Promise { - return [await this.contract.getMessageHash(...args)] - } - - signMessage: SignMessageFunction = - async (data, options) => { - if (options && !options.gasLimit) { - options.gasLimit = Number(await this.estimateGas('signMessage', data, { ...options })) - } - - const txResponse = await this.contract.signMessage(data, { ...options }) - - return toTxResult(txResponse, options) - } - // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): SignMessageLibContract { return { diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractEthers.ts index 4257a8f19..63ab75f51 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractEthers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractEthers.ts @@ -1,29 +1,28 @@ -import { Contract, ContractRunner, InterfaceAbi } from 'ethers' +import { Abi } from 'abitype' +import { ContractRunner, InterfaceAbi } from 'ethers' +import BaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/BaseContractEthers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' -import SimulateTxAccessorBaseContract from '@safe-global/protocol-kit/adapters/SimulateTxAccessorBaseContract' import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import { contractName } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class SimulateTxAccessorBaseContractEthers extends SimulateTxAccessorBaseContract to specifically integrate with the Ethers.js v6 library. + * Abstract class SimulateTxAccessorBaseContractEthers extends BaseContractEthers to specifically integrate with the SimulateTxAccessor contract. * 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 SimulateTxAccessor contract version. - * * Subclasses of SimulateTxAccessorBaseContractEthers are expected to represent specific versions of the contract. * * @template SimulateTxAccessorContractAbiType - The ABI type specific to the version of the SimulateTxAccessor contract, extending InterfaceAbi from Ethers. - * @extends SimulateTxAccessorBaseContract - Extends the generic SimulateTxAccessorBaseContract with Ethers-specific implementation. + * @extends BaseContractEthers - Extends the generic BaseContractEthers. * * Example subclasses: * - SimulateTxAccessorContract_v1_4_1_Ethers extends SimulateTxAccessorBaseContractEthers * - SimulateTxAccessorContract_v1_3_0_Ethers extends SimulateTxAccessorBaseContractEthers */ abstract class SimulateTxAccessorBaseContractEthers< - SimulateTxAccessorContractAbiType extends InterfaceAbi -> extends SimulateTxAccessorBaseContract { - contract: Contract - adapter: EthersAdapter + SimulateTxAccessorContractAbiType extends InterfaceAbi & Abi +> extends BaseContractEthers { + contractName: contractName /** * @constructor @@ -45,14 +44,20 @@ abstract class SimulateTxAccessorBaseContractEthers< customContractAbi?: SimulateTxAccessorContractAbiType, runner?: ContractRunner | null ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'simulateTxAccessorVersion' - this.adapter = ethersAdapter - this.contract = new Contract( - this.contractAddress, - this.contractAbi, - runner || this.adapter.getSigner() + super( + contractName, + chainId, + ethersAdapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi, + runner ) + + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Ethers.ts index 091e21f93..95e130d05 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Ethers.ts @@ -1,14 +1,11 @@ import SimulateTxAccessorBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractEthers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' import SimulateTxAccessorContract_v1_3_0_Contract, { - SimulateTxAccessorContract_v1_3_0_Abi + SimulateTxAccessorContract_v1_3_0_Abi, + SimulateTxAccessorContract_v1_3_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0' import SimulateTxAccessor_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SimulateTxAccessor/v1.3.0/simulate_tx_accessor' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeSimulateTxAccessorFunction, - GetAddressSimulateTxAccessorFunction -} from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract' /** * SimulateTxAccessorContract_v1_3_0_Ethers is the implementation specific to the SimulateTxAccessor contract version 1.3.0. @@ -46,20 +43,11 @@ class SimulateTxAccessorContract_v1_3_0_Ethers this.safeVersion = safeVersion } - getAddress: GetAddressSimulateTxAccessorFunction = () => { - return this.contract.getAddress() - } - - encode: EncodeSimulateTxAccessorFunction = ( - functionToEncode, - args - ) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } - - simulate: SimulateTxAccessorContract_v1_3_0_Contract['simulate'] = ( - args: readonly [to: string, value: bigint, data: string, operation: number] - ) => { + /** + * @param args - Array[to, value, data, operation] + * @returns Array[estimate, success, returnData] + */ + simulate: SimulateTxAccessorContract_v1_3_0_Function<'simulate'> = (args) => { return this.contract.simulate(...args) } } diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Ethers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Ethers.ts index 19d42e26a..f4d5de96c 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Ethers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Ethers.ts @@ -1,14 +1,11 @@ import SimulateTxAccessorBaseContractEthers from '@safe-global/protocol-kit/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractEthers' import EthersAdapter from '@safe-global/protocol-kit/adapters/ethers/EthersAdapter' import SimulateTxAccessorContract_v1_4_1_Contract, { - SimulateTxAccessorContract_v1_4_1_Abi + SimulateTxAccessorContract_v1_4_1_Abi, + SimulateTxAccessorContract_v1_4_1_Function } from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1' import SimulateTxAccessor_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SimulateTxAccessor/v1.4.1/simulate_tx_accessor' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeSimulateTxAccessorFunction, - GetAddressSimulateTxAccessorFunction -} from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract' /** * SimulateTxAccessorContract_v1_4_1_Ethers is the implementation specific to the SimulateTxAccessor contract version 1.4.1. @@ -46,20 +43,11 @@ class SimulateTxAccessorContract_v1_4_1_Ethers this.safeVersion = safeVersion } - getAddress: GetAddressSimulateTxAccessorFunction = () => { - return this.contract.getAddress() - } - - encode: EncodeSimulateTxAccessorFunction = ( - functionToEncode, - args - ) => { - return this.contract.interface.encodeFunctionData(functionToEncode, args) - } - - simulate: SimulateTxAccessorContract_v1_4_1_Contract['simulate'] = ( - args: readonly [to: string, value: bigint, data: string, operation: number] - ) => { + /** + * @param args - Array[to, value, data, operation] + * @returns Array[estimate, success, returnData] + */ + simulate: SimulateTxAccessorContract_v1_4_1_Function<'simulate'> = (args) => { return this.contract.simulate(...args) } } diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts index a89049087..f6a1a50c3 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts @@ -1,24 +1,21 @@ import { AbstractSigner, Provider } from 'ethers' import { AbiItem } from 'web3-utils' -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 { 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 { + CompatibilityFallbackHandlerContract, CreateCallContract, SafeVersion, SignMessageLibContract, SimulateTxAccessorContract } from '@safe-global/safe-core-sdk-types' -import CompatibilityFallbackHandler_V1_3_0_Ethers from './CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandler_V1_3_0_Ethers' -import CompatibilityFallbackHandler_V1_4_1_Ethers from './CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandler_V1_4_1_Ethers' -import CreateCallContract_V1_3_0_Ethers from './CreateCall/v1.3.0/CreateCallContract_v1_3_0_Ethers' -import CreateCallContract_V1_4_1_Ethers from './CreateCall/v1.4.1/CreateCallContract_v1_4_1_Ethers' -import MultiSendContract_V1_1_1_Ethers from './MultiSend/v1.1.1/MultiSendContract_V1_1_1_Ethers' -import MultiSendContract_V1_3_0_Ethers from './MultiSend/v1.3.0/MultiSendContract_V1_3_0_Ethers' -import MultiSendContract_V1_4_1_Ethers from './MultiSend/v1.4.1/MultiSendContract_V1_4_1_Ethers' -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 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 CreateCallContract_V1_3_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/CreateCall/v1.3.0/CreateCallContract_v1_3_0_Ethers' +import CreateCallContract_V1_4_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/CreateCall/v1.4.1/CreateCallContract_v1_4_1_Ethers' +import MultiSendContract_V1_1_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/MultiSend/v1.1.1/MultiSendContract_V1_1_1_Ethers' +import MultiSendContract_V1_3_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/MultiSend/v1.3.0/MultiSendContract_V1_3_0_Ethers' +import MultiSendContract_V1_4_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/MultiSend/v1.4.1/MultiSendContract_V1_4_1_Ethers' +import MultiSendCallOnlyContract_V1_3_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Ethers' +import MultiSendCallOnlyContract_V1_4_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Ethers' +import SignMessageLibContract_V1_3_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Ethers' +import SignMessageLibContract_V1_4_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Ethers' import SafeContract_v1_0_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/Safe/v1.0.0/SafeContract_v1_0_0_Ethers' 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' @@ -30,7 +27,8 @@ import SafeProxyFactoryContract_v1_3_0_Ethers from '@safe-global/protocol-kit/ad import SafeProxyFactoryContract_v1_4_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Ethers' import SimulateTxAccessorContract_V1_3_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Ethers' import SimulateTxAccessorContract_V1_4_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Ethers' -import EthersAdapter from '../EthersAdapter' +import CompatibilityFallbackHandlerContract_v1_3_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0_Ethers' +import CompatibilityFallbackHandlerContract_v1_4_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1_Ethers' import { CreateCallContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/v1.4.1/CreateCallContract_v1_4_1' import { CreateCallContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/v1.3.0/CreateCallContract_v1_3_0' import { MultiSendContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.4.1/MultiSendContract_v1_4_1' @@ -51,6 +49,9 @@ import { SafeProxyFactoryContract_v1_3_0_Abi } from '@safe-global/protocol-kit/c import { SafeProxyFactoryContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1' import { SimulateTxAccessorContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0' import { SimulateTxAccessorContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1' +import { CompatibilityFallbackHandlerContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0' +import { CompatibilityFallbackHandlerContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1' +import EthersAdapter from '../EthersAdapter' export async function getSafeContractInstance( safeVersion: SafeVersion, @@ -123,27 +124,30 @@ export async function getSafeContractInstance( } } -export function getCompatibilityFallbackHandlerContractInstance( +export async function getCompatibilityFallbackHandlerContractInstance( safeVersion: SafeVersion, contractAddress: string, - signerOrProvider: AbstractSigner | Provider -): CompatibilityFallbackHandler_V1_4_1_Ethers | CompatibilityFallbackHandler_V1_3_0_Ethers { - let compatibilityFallbackHandlerContract + ethersAdapter: EthersAdapter, + customContractAbi?: AbiItem | AbiItem[] | undefined +): Promise { + const chainId = await ethersAdapter.getChainId() switch (safeVersion) { case '1.4.1': - compatibilityFallbackHandlerContract = CompatibilityFallbackHandler_V1_4_1.connect( + return new CompatibilityFallbackHandlerContract_v1_4_1_Ethers( + chainId, + ethersAdapter, contractAddress, - signerOrProvider + customContractAbi as unknown as CompatibilityFallbackHandlerContract_v1_4_1_Abi ) - return new CompatibilityFallbackHandler_V1_4_1_Ethers(compatibilityFallbackHandlerContract) case '1.3.0': case '1.2.0': case '1.1.1': - compatibilityFallbackHandlerContract = CompatibilityFallbackHandler_V1_3_0.connect( + return new CompatibilityFallbackHandlerContract_v1_3_0_Ethers( + chainId, + ethersAdapter, contractAddress, - signerOrProvider + customContractAbi as unknown as CompatibilityFallbackHandlerContract_v1_3_0_Abi ) - return new CompatibilityFallbackHandler_V1_3_0_Ethers(compatibilityFallbackHandlerContract) default: throw new Error('Invalid Safe version') } diff --git a/packages/protocol-kit/src/adapters/web3/Web3Adapter.ts b/packages/protocol-kit/src/adapters/web3/Web3Adapter.ts index fdb061187..f69540233 100644 --- a/packages/protocol-kit/src/adapters/web3/Web3Adapter.ts +++ b/packages/protocol-kit/src/adapters/web3/Web3Adapter.ts @@ -1,6 +1,7 @@ import { generateTypedData, validateEip3770Address } from '@safe-global/protocol-kit/utils' import { SigningMethod } from '@safe-global/protocol-kit/types' import { + CompatibilityFallbackHandlerContract, CreateCallContract, Eip3770Address, EthAdapter, @@ -18,7 +19,6 @@ import { AbiItem } from 'web3-utils' // Deprecated https://www.npmjs.com/package/@types/web3?activeTab=readme // Migration guide https://docs.web3js.org/docs/guides/web3_migration_guide#types import type { JsonRPCResponse, Provider } from 'web3/providers' -import CompatibilityFallbackHandlerWeb3Contract from './contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerWeb3Contract' import SafeContractWeb3 from './contracts/Safe/SafeContractWeb3' import { getCompatibilityFallbackHandlerContractInstance, @@ -173,18 +173,19 @@ class Web3Adapter implements EthAdapter { singletonDeployment, customContractAddress, customContractAbi - }: GetContractProps): Promise { + }: GetContractProps): Promise { const chainId = await this.getChainId() const contractAddress = customContractAddress ?? singletonDeployment?.networkAddresses[chainId.toString()] if (!contractAddress) { throw new Error('Invalid Compatibility Fallback Handler contract address') } - const multiSendContract = this.getContract( + return getCompatibilityFallbackHandlerContractInstance( + safeVersion, contractAddress, - customContractAbi ?? (singletonDeployment?.abi as AbiItem[]) + this, + customContractAbi ) - return getCompatibilityFallbackHandlerContractInstance(safeVersion, multiSendContract) } async getSignMessageLibContract({ diff --git a/packages/protocol-kit/src/adapters/web3/contracts/BaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/BaseContractWeb3.ts new file mode 100644 index 000000000..f0c6df5d8 --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/BaseContractWeb3.ts @@ -0,0 +1,84 @@ +import { Abi } from 'abitype' +import Contract from 'web3-eth-contract' +import { AbiItem } from 'web3-utils' + +import { contractName } from '@safe-global/protocol-kit/contracts/config' +import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import { + EncodeFunction, + EstimateGasFunction, + GetAddressFunction +} from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' +import BaseContract from '@safe-global/protocol-kit/adapters/BaseContract' +import { Web3TransactionOptions } from '@safe-global/protocol-kit/adapters/web3/types' + +/** + * Abstract class BaseContractWeb3 extends BaseContract to specifically integrate with the Web3.js library. + * It is designed to be instantiated for different contracts. + * + * This abstract class sets up the Web3 Contract object that interacts with the smart contract. + * + * Subclasses of BaseContractWeb3 are expected to represent specific contracts. + * + * @template ContractAbiType - The ABI type specific to the version of the contract, extending InterfaceAbi from Web3. + * @extends BaseContract - Extends the generic BaseContract with Web3-specific implementation. + * + * Example subclasses: + * - SafeBaseContractWeb3 extends BaseContractWeb3 + * - CreateCallBaseContractWeb3 extends BaseContractWeb3 + * - SafeProxyFactoryBaseContractWeb3 extends BaseContractWeb3 + */ +abstract class BaseContractWeb3< + ContractAbiType extends AbiItem[] & Abi +> extends BaseContract { + contract: Contract + adapter: Web3Adapter + + /** + * @constructor + * Constructs an instance of BaseContractWeb3. + * + * @param contractName - The contract name. + * @param chainId - The chain ID of the contract. + * @param web3Adapter - An instance of Web3Adapter. + * @param defaultAbi - The default ABI for the 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( + contractName: contractName, + chainId: bigint, + web3Adapter: Web3Adapter, + defaultAbi: ContractAbiType, + safeVersion: SafeVersion, + customContractAddress?: string, + customContractAbi?: ContractAbiType + ) { + super(contractName, chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + + this.adapter = web3Adapter + this.contract = web3Adapter.getContract(this.contractAddress, this.contractAbi) + } + + getAddress: GetAddressFunction = () => { + return Promise.resolve(this.contract.options.address) + } + + encode: EncodeFunction = (functionToEncode, args) => { + return this.contract.methods[functionToEncode](...(args as Array)).encodeABI() + } + + estimateGas: EstimateGasFunction = ( + functionToEstimate, + args, + options = {} + ) => { + return this.contract.methods[functionToEstimate](...(args as Array)) + .estimateGas(options) + .then(BigInt) + } +} + +export default BaseContractWeb3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContractWeb3.ts new file mode 100644 index 000000000..b65623ffc --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContractWeb3.ts @@ -0,0 +1,62 @@ +import { Abi } from 'abitype' +import { AbiItem } from 'web3-utils' + +import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' +import BaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/BaseContractWeb3' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import { contractName } from '@safe-global/protocol-kit/contracts/config' + +/** + * Abstract class CompatibilityFallbackHandlerBaseContractWeb3 extends BaseContractWeb3 to specifically integrate with the CompatibilityFallbackHandler contract. + * It is designed to be instantiated for different versions of the Safe contract. + * + * Subclasses of CompatibilityFallbackHandlerBaseContractWeb3 are expected to represent specific versions of the contract. + * + * @template CompatibilityFallbackHandlerContractAbiType - The ABI type specific to the version of the CompatibilityFallbackHandler contract, extending InterfaceAbi from Web3. + * @extends BaseContractWeb3 - Extends the generic BaseContractWeb3. + * + * Example subclasses: + * - CompatibilityFallbackHandlerContract_v1_4_1_Web3 extends CompatibilityFallbackHandlerBaseContractWeb3 + * - CompatibilityFallbackHandlerContract_v1_3_0_Web3 extends CompatibilityFallbackHandlerBaseContractWeb3 + */ +abstract class CompatibilityFallbackHandlerBaseContractWeb3< + CompatibilityFallbackHandlerContractAbiType extends AbiItem[] & Abi +> extends BaseContractWeb3 { + contractName: contractName + + /** + * @constructor + * Constructs an instance of CompatibilityFallbackHandlerBaseContractWeb3. + * + * @param chainId - The chain ID of the contract. + * @param web3Adapter - An instance of Web3Adapter. + * @param defaultAbi - The default ABI for the CompatibilityFallbackHandler 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: CompatibilityFallbackHandlerContractAbiType, + safeVersion: SafeVersion, + customContractAddress?: string, + customContractAbi?: CompatibilityFallbackHandlerContractAbiType + ) { + const contractName = 'compatibilityFallbackHandler' + + super( + contractName, + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi + ) + + this.contractName = contractName + } +} + +export default CompatibilityFallbackHandlerBaseContractWeb3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerWeb3Contract.ts b/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerWeb3Contract.ts deleted file mode 100644 index 8daaab819..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerWeb3Contract.ts +++ /dev/null @@ -1,21 +0,0 @@ -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 { Compatibility_fallback_handler as CompatibilityFallbackHandler_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Compatibility_fallback_handler' -import { CompatibilityFallbackHandlerContract } from '@safe-global/safe-core-sdk-types' - -abstract class CompatibilityFallbackHandlerWeb3Contract - implements CompatibilityFallbackHandlerContract -{ - constructor( - public contract: CompatibilityFallbackHandler_V1_4_1 | CompatibilityFallbackHandler_V1_3_0 - ) {} - - getAddress(): Promise { - return Promise.resolve(this.contract.options.address) - } - - encode(methodName: string, params: any[]): string { - return (this.contract as any).methods[methodName](...params).encodeABI() - } -} - -export default CompatibilityFallbackHandlerWeb3Contract diff --git a/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0_Web3.ts new file mode 100644 index 000000000..c79a6900a --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0_Web3.ts @@ -0,0 +1,57 @@ +import CompatibilityFallbackHandlerBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContractWeb3' +import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' +import { DeepWriteable } from '@safe-global/protocol-kit/adapters/web3/types' +import CompatibilityFallbackHandlerContract_v1_3_0_Contract, { + CompatibilityFallbackHandlerContract_v1_3_0_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0' +import CompatibilityFallbackHandler_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.3.0/compatibility_fallback_handler' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * CompatibilityFallbackHandlerContract_v1_3_0_Web3 is the implementation specific to the CompatibilityFallbackHandler contract version 1.3.0. + * + * This class specializes in handling interactions with the CompatibilityFallbackHandler contract version 1.3.0 using Web3.js. + * + * @extends CompatibilityFallbackHandlerBaseContractWeb3 - Inherits from CompatibilityFallbackHandlerBaseContractWeb3 with ABI specific to CompatibilityFallbackHandler contract version 1.3.0. + * @implements CompatibilityFallbackHandlerContract_v1_3_0_Contract - Implements the interface specific to CompatibilityFallbackHandler contract version 1.3.0. + */ +class CompatibilityFallbackHandlerContract_v1_3_0_Web3 + extends CompatibilityFallbackHandlerBaseContractWeb3< + DeepWriteable + > + implements CompatibilityFallbackHandlerContract_v1_3_0_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of CompatibilityFallbackHandlerContract_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 CompatibilityFallbackHandler 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?: CompatibilityFallbackHandlerContract_v1_3_0_Abi + ) { + const safeVersion = '1.3.0' + const defaultAbi = + CompatibilityFallbackHandler_1_3_0_ContractArtifacts.abi as DeepWriteable + + super( + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi as DeepWriteable + ) + + this.safeVersion = safeVersion + } +} + +export default CompatibilityFallbackHandlerContract_v1_3_0_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandler_V1_3_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandler_V1_3_0_Web3.ts deleted file mode 100644 index 3d179d43a..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandler_V1_3_0_Web3.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Compatibility_fallback_handler as CompatibilityFallbackHandler } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Compatibility_fallback_handler' -import CompatibilityFallbackHandlerWeb3Contract from '../CompatibilityFallbackHandlerWeb3Contract' - -class CompatibilityFallbackHandler_V1_3_0_Web3 extends CompatibilityFallbackHandlerWeb3Contract { - constructor(public contract: CompatibilityFallbackHandler) { - super(contract) - } -} - -export default CompatibilityFallbackHandler_V1_3_0_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1_Web3.ts new file mode 100644 index 000000000..f95718119 --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1_Web3.ts @@ -0,0 +1,57 @@ +import CompatibilityFallbackHandlerBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContractWeb3' +import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' +import { DeepWriteable } from '@safe-global/protocol-kit/adapters/web3/types' +import CompatibilityFallbackHandlerContract_v1_4_1_Contract, { + CompatibilityFallbackHandlerContract_v1_4_1_Abi +} from '@safe-global/protocol-kit/contracts/AbiType/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1' +import CompatibilityFallbackHandler_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.4.1/compatibility_fallback_handler' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +/** + * CompatibilityFallbackHandlerContract_v1_4_1_Web3 is the implementation specific to the CompatibilityFallbackHandler contract version 1.4.1. + * + * This class specializes in handling interactions with the CompatibilityFallbackHandler contract version 1.4.1 using Web3.js. + * + * @extends CompatibilityFallbackHandlerBaseContractWeb3 - Inherits from CompatibilityFallbackHandlerBaseContractWeb3 with ABI specific to CompatibilityFallbackHandler contract version 1.4.1. + * @implements CompatibilityFallbackHandlerContract_v1_4_1_Contract - Implements the interface specific to CompatibilityFallbackHandler contract version 1.4.1. + */ +class CompatibilityFallbackHandlerContract_v1_4_1_Web3 + extends CompatibilityFallbackHandlerBaseContractWeb3< + DeepWriteable + > + implements CompatibilityFallbackHandlerContract_v1_4_1_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of CompatibilityFallbackHandlerContract_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 CompatibilityFallbackHandler 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?: CompatibilityFallbackHandlerContract_v1_4_1_Abi + ) { + const safeVersion = '1.4.1' + const defaultAbi = + CompatibilityFallbackHandler_1_4_1_ContractArtifacts.abi as DeepWriteable + + super( + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi as DeepWriteable + ) + + this.safeVersion = safeVersion + } +} + +export default CompatibilityFallbackHandlerContract_v1_4_1_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandler_V1_4_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandler_V1_4_1_Web3.ts deleted file mode 100644 index 0670913ab..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandler_V1_4_1_Web3.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Compatibility_fallback_handler as CompatibilityFallbackHandler } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Compatibility_fallback_handler' -import CompatibilityFallbackHandlerWeb3Contract from '../CompatibilityFallbackHandlerWeb3Contract' - -class CompatibilityFallbackHandler_V1_4_1_Web3 extends CompatibilityFallbackHandlerWeb3Contract { - constructor(public contract: CompatibilityFallbackHandler) { - super(contract) - } -} - -export default CompatibilityFallbackHandler_V1_4_1_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/CreateCallBaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/CreateCallBaseContractWeb3.ts index cf7b0e0dc..192a4e472 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/CreateCallBaseContractWeb3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/CreateCallBaseContractWeb3.ts @@ -1,30 +1,28 @@ -import Contract from 'web3-eth-contract' +import { Abi } from 'abitype' import { AbiItem } from 'web3-utils' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' -import CreateCallBaseContract from '@safe-global/protocol-kit/adapters/CreateCallBaseContract' +import BaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/BaseContractWeb3' import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import { contractName } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class CreateCallBaseContractWeb3 extends CreateCallBaseContract to specifically integrate with the Web3.js v6 library. + * Abstract class CreateCallBaseContractWeb3 extends BaseContractWeb3 to specifically integrate with the CreateCall contract. * It is designed to be instantiated for different versions of the Safe contract. * - * This abstract class sets up the Web3 v6 Contract object that interacts with a CreateCall contract version. - * * Subclasses of CreateCallBaseContractWeb3 are expected to represent specific versions of the contract. * * @template CreateCallContractAbiType - The ABI type specific to the version of the CreateCall contract, extending InterfaceAbi from Web3. - * @extends CreateCallBaseContract - Extends the generic CreateCallBaseContract with Web3-specific implementation. + * @extends BaseContractWeb3 - Extends the generic BaseContractWeb3. * * Example subclasses: * - CreateCallContract_v1_4_1_Web3 extends CreateCallBaseContractWeb3 * - CreateCallContract_v1_3_0_Web3 extends CreateCallBaseContractWeb3 */ abstract class CreateCallBaseContractWeb3< - CreateCallContractAbiType extends AbiItem[] -> extends CreateCallBaseContract { - contract: Contract - adapter: Web3Adapter + CreateCallContractAbiType extends AbiItem[] & Abi +> extends BaseContractWeb3 { + contractName: contractName /** * @constructor @@ -45,10 +43,19 @@ abstract class CreateCallBaseContractWeb3< customContractAddress?: string, customContractAbi?: CreateCallContractAbiType ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'createCallVersion' + + super( + contractName, + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi + ) - this.adapter = web3Adapter - this.contract = web3Adapter.getContract(this.contractAddress, this.contractAbi) + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/v1.3.0/CreateCallContract_v1_3_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/v1.3.0/CreateCallContract_v1_3_0_Web3.ts index 3d3442b6b..a96708392 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/v1.3.0/CreateCallContract_v1_3_0_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/v1.3.0/CreateCallContract_v1_3_0_Web3.ts @@ -2,20 +2,18 @@ import CreateCallBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/ import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import { DeepWriteable, - Web3TransactionOptions, - Web3TransactionResult + Web3TransactionOptions } from '@safe-global/protocol-kit/adapters/web3/types' import CreateCallContract_v1_3_0_Contract, { - CreateCallContract_v1_3_0_Abi + CreateCallContract_v1_3_0_Abi as CreateCallContract_v1_3_0_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/v1.3.0/CreateCallContract_v1_3_0' import CreateCall_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CreateCall/v1.3.0/create_call' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeCreateCallFunction, - EstimateGasCreateCallFunction, - GetAddressCreateCallFunction -} from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/CreateCallBaseContract' import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' +import { AdapterSpecificContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' + +// Remove all nested `readonly` modifiers from the ABI type +type CreateCallContract_v1_3_0_Abi = DeepWriteable /** * CreateCallContract_V1_3_0_Web3 is the implementation specific to the CreateCall contract version 1.3.0. @@ -26,8 +24,8 @@ import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' * @implements CreateCallContract_v1_3_0_Contract - Implements the interface specific to CreateCall contract version 1.3.0. */ class CreateCallContract_V1_3_0_Web3 - extends CreateCallBaseContractWeb3> - implements CreateCallContract_v1_3_0_Contract + extends CreateCallBaseContractWeb3 + implements CreateCallContract_v1_3_0_Contract { safeVersion: SafeVersion @@ -46,8 +44,7 @@ class CreateCallContract_V1_3_0_Web3 customContractAbi?: CreateCallContract_v1_3_0_Abi ) { const safeVersion = '1.3.0' - const defaultAbi = - CreateCall_1_3_0_ContractArtifacts.abi as DeepWriteable + const defaultAbi = CreateCall_1_3_0_ContractArtifacts.abi as CreateCallContract_v1_3_0_Abi super( chainId, @@ -55,50 +52,43 @@ class CreateCallContract_V1_3_0_Web3 defaultAbi, safeVersion, customContractAddress, - customContractAbi as DeepWriteable + customContractAbi as CreateCallContract_v1_3_0_Abi ) this.safeVersion = safeVersion } - getAddress: GetAddressCreateCallFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - encode: EncodeCreateCallFunction = (functionToEncode, args) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - estimateGas: EstimateGasCreateCallFunction< - CreateCallContract_v1_3_0_Abi, - Web3TransactionOptions - > = async (functionToEstimate, args, options = {}) => { - return ( - await this.contract.methods[functionToEstimate](...args).estimateGas(options) - ).toString() - } - - async performCreate( - args: readonly [value: bigint, deploymentData: string], - options?: Web3TransactionOptions - ): Promise { - if (options && !options.gas) { - options.gas = (await this.estimateGas('performCreate', args, { ...options })).toString() + /** + * @param args - Array[value, deploymentData] + * @param options - Web3TransactionOptions + * @returns Promise + */ + performCreate: AdapterSpecificContractFunction = + async (args, options) => { + if (options && !options.gas) { + options.gas = ( + await this.estimateGas('performCreate', [...args], { ...options }) + ).toString() + } + const txResponse = this.contract.methods.performCreate(...args).send(options) + return toTxResult(txResponse, options) } - const txResponse = this.contract.methods.performCreate(...args).send(options) - return toTxResult(txResponse, options) - } - async performCreate2( - args: readonly [value: bigint, deploymentData: string, salt: string], - options?: Web3TransactionOptions - ): Promise { - if (options && !options.gas) { - options.gas = (await this.estimateGas('performCreate2', args, { ...options })).toString() + /** + * @param args - Array[value, deploymentData, salt] + * @param options - Web3TransactionOptions + * @returns Promise + */ + performCreate2: AdapterSpecificContractFunction = + async (args, options) => { + if (options && !options.gas) { + options.gas = ( + await this.estimateGas('performCreate2', [...args], { ...options }) + ).toString() + } + const txResponse = this.contract.methods.performCreate2(...args).send(options) + return toTxResult(txResponse, options) } - const txResponse = this.contract.methods.performCreate2(...args).send(options) - return toTxResult(txResponse, options) - } // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): any { diff --git a/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/v1.4.1/CreateCallContract_v1_4_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/v1.4.1/CreateCallContract_v1_4_1_Web3.ts index ce962ad63..c1f22debc 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/v1.4.1/CreateCallContract_v1_4_1_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/CreateCall/v1.4.1/CreateCallContract_v1_4_1_Web3.ts @@ -2,20 +2,18 @@ import CreateCallBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/ import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import { DeepWriteable, - Web3TransactionOptions, - Web3TransactionResult + Web3TransactionOptions } from '@safe-global/protocol-kit/adapters/web3/types' import CreateCallContract_v1_4_1_Contract, { - CreateCallContract_v1_4_1_Abi + CreateCallContract_v1_4_1_Abi as CreateCallContract_v1_4_1_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/v1.4.1/CreateCallContract_v1_4_1' import CreateCall_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CreateCall/v1.4.1/create_call' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeCreateCallFunction, - EstimateGasCreateCallFunction, - GetAddressCreateCallFunction -} from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/CreateCallBaseContract' import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' +import { AdapterSpecificContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' + +// Remove all nested `readonly` modifiers from the ABI type +type CreateCallContract_v1_4_1_Abi = DeepWriteable /** * CreateCallContract_V1_4_1_Web3 is the implementation specific to the CreateCall contract version 1.4.1. @@ -26,8 +24,8 @@ import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' * @implements CreateCallContract_v1_4_1_Contract - Implements the interface specific to CreateCall contract version 1.4.1. */ class CreateCallContract_V1_4_1_Web3 - extends CreateCallBaseContractWeb3> - implements CreateCallContract_v1_4_1_Contract + extends CreateCallBaseContractWeb3 + implements CreateCallContract_v1_4_1_Contract { safeVersion: SafeVersion @@ -46,8 +44,7 @@ class CreateCallContract_V1_4_1_Web3 customContractAbi?: CreateCallContract_v1_4_1_Abi ) { const safeVersion = '1.4.1' - const defaultAbi = - CreateCall_1_4_1_ContractArtifacts.abi as DeepWriteable + const defaultAbi = CreateCall_1_4_1_ContractArtifacts.abi as CreateCallContract_v1_4_1_Abi super( chainId, @@ -55,50 +52,43 @@ class CreateCallContract_V1_4_1_Web3 defaultAbi, safeVersion, customContractAddress, - customContractAbi as DeepWriteable + customContractAbi as CreateCallContract_v1_4_1_Abi ) this.safeVersion = safeVersion } - getAddress: GetAddressCreateCallFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - encode: EncodeCreateCallFunction = (functionToEncode, args) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - estimateGas: EstimateGasCreateCallFunction< - CreateCallContract_v1_4_1_Abi, - Web3TransactionOptions - > = async (functionToEstimate, args, options = {}) => { - return ( - await this.contract.methods[functionToEstimate](...args).estimateGas(options) - ).toString() - } - - async performCreate( - args: readonly [value: bigint, deploymentData: string], - options?: Web3TransactionOptions - ): Promise { - if (options && !options.gas) { - options.gas = (await this.estimateGas('performCreate', args, { ...options })).toString() + /** + * @param args - Array[value, deploymentData] + * @param options - Web3TransactionOptions + * @returns Promise + */ + performCreate: AdapterSpecificContractFunction = + async (args, options) => { + if (options && !options.gas) { + options.gas = ( + await this.estimateGas('performCreate', [...args], { ...options }) + ).toString() + } + const txResponse = this.contract.methods.performCreate(...args).send(options) + return toTxResult(txResponse, options) } - const txResponse = this.contract.methods.performCreate(...args).send(options) - return toTxResult(txResponse, options) - } - async performCreate2( - args: readonly [value: bigint, deploymentData: string, salt: string], - options?: Web3TransactionOptions - ): Promise { - if (options && !options.gas) { - options.gas = (await this.estimateGas('performCreate2', args, { ...options })).toString() + /** + * @param args - Array[value, deploymentData, salt] + * @param options - Web3TransactionOptions + * @returns Promise + */ + performCreate2: AdapterSpecificContractFunction = + async (args, options) => { + if (options && !options.gas) { + options.gas = ( + await this.estimateGas('performCreate2', [...args], { ...options }) + ).toString() + } + const txResponse = this.contract.methods.performCreate2(...args).send(options) + return toTxResult(txResponse, options) } - const txResponse = this.contract.methods.performCreate2(...args).send(options) - return toTxResult(txResponse, options) - } // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): any { diff --git a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/MultiSendBaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/MultiSendBaseContractWeb3.ts index 2ec4bf6aa..742462d12 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/MultiSendBaseContractWeb3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/MultiSendBaseContractWeb3.ts @@ -1,30 +1,28 @@ -import Contract from 'web3-eth-contract' +import { Abi } from 'abitype' import { AbiItem } from 'web3-utils' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import MultiSendBaseContract from '@safe-global/protocol-kit/adapters/MultiSendBaseContract' +import BaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/BaseContractWeb3' +import { contractName } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class MultiSendBaseContractWeb3 extends MultiSendBaseContract to specifically integrate with the Web3.js v6 library. + * Abstract class MultiSendBaseContractWeb3 extends BaseContractWeb3 to specifically integrate with the MultiSend contract. * It is designed to be instantiated for different versions of the MultiSend contract. * - * This abstract class sets up the Web3 v6 Contract object that interacts with a MultiSend contract version. - * * Subclasses of MultiSendBaseContractWeb3 are expected to represent specific versions of the MultiSend contract. * * @template MultiSendContractAbiType - The ABI type specific to the version of the MultiSend contract, extending InterfaceAbi from Web3. - * @extends MultiSendBaseContract - Extends the generic MultiSendBaseContract with Web3-specific implementation. + * @extends BaseContractWeb3 - Extends the generic BaseContractWeb3. * * Example subclasses: * - MultiSendContract_v1_4_1_Web3 extends MultiSendBaseContractWeb3 * - MultiSendContract_v1_3_0_Web3 extends MultiSendBaseContractWeb3 */ abstract class MultiSendBaseContractWeb3< - MultiSendContractAbiType extends AbiItem[] -> extends MultiSendBaseContract { - contract: Contract - adapter: Web3Adapter + MultiSendContractAbiType extends AbiItem[] & Abi +> extends BaseContractWeb3 { + contractName: contractName /** * @constructor @@ -45,10 +43,19 @@ abstract class MultiSendBaseContractWeb3< customContractAddress?: string, customContractAbi?: MultiSendContractAbiType ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'multiSendVersion' + + super( + contractName, + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi + ) - this.adapter = web3Adapter - this.contract = web3Adapter.getContract(this.contractAddress, this.contractAbi) + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/MultiSendCallOnlyBaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/MultiSendCallOnlyBaseContractWeb3.ts index f776cf0ad..7b8344958 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/MultiSendCallOnlyBaseContractWeb3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/MultiSendCallOnlyBaseContractWeb3.ts @@ -1,30 +1,28 @@ -import Contract from 'web3-eth-contract' +import { Abi } from 'abitype' import { AbiItem } from 'web3-utils' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import MultiSendCallOnlyBaseContract from '@safe-global/protocol-kit/adapters/MultiSendCallOnlyBaseContract' +import BaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/BaseContractWeb3' +import { contractName } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class MultiSendBaseContractWeb3 extends MultiSendCallOnlyBaseContract to specifically integrate with the Web3.js v6 library. + * Abstract class MultiSendCallOnlyBaseContractWeb3 extends BaseContractWeb3 to specifically integrate with the MultiSendCallOnly contract. * It is designed to be instantiated for different versions of the MultiSendCallOnly contract. * - * This abstract class sets up the Web3 v6 Contract object that interacts with a MultiSendCallOnly contract version. - * * Subclasses of MultiSendCallOnlyBaseContractWeb3 are expected to represent specific versions of the MultiSendCallOnly contract. * * @template MultiSendCallOnlyContractAbiType - The ABI type specific to the version of the MultiSendCallOnly contract, extending InterfaceAbi from Web3. - * @extends MultiSendCallOnlyBaseContract - Extends the generic MultiSendCallOnlyBaseContract with Web3-specific implementation. + * @extends BaseContractWeb3 - Extends the generic BaseContractWeb3. * * Example subclasses: * - MultiSendCallOnlyContract_v1_4_1_Web3 extends MultiSendCallOnlyBaseContractWeb3 * - MultiSendCallOnlyContract_v1_3_0_Web3 extends MultiSendCallOnlyBaseContractWeb3 */ abstract class MultiSendCallOnlyBaseContractWeb3< - MultiSendCallOnlyContractAbiType extends AbiItem[] -> extends MultiSendCallOnlyBaseContract { - contract: Contract - adapter: Web3Adapter + MultiSendCallOnlyContractAbiType extends AbiItem[] & Abi +> extends BaseContractWeb3 { + contractName: contractName /** * @constructor @@ -45,10 +43,19 @@ abstract class MultiSendCallOnlyBaseContractWeb3< customContractAddress?: string, customContractAbi?: MultiSendCallOnlyContractAbiType ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'multiSendCallOnlyVersion' + + super( + contractName, + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi + ) - this.adapter = web3Adapter - this.contract = web3Adapter.getContract(this.contractAddress, this.contractAbi) + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.1.1/MultiSendContract_V1_1_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.1.1/MultiSendContract_V1_1_1_Web3.ts index 7343a588e..b58ce78ff 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.1.1/MultiSendContract_V1_1_1_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.1.1/MultiSendContract_V1_1_1_Web3.ts @@ -6,10 +6,6 @@ import MultiSendContract_v1_1_1_Contract, { } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.1.1/MultiSendContract_v1_1_1' import multiSend_1_1_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/MultiSend/v1.1.1/multi_send' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeMultiSendFunction, - GetAddressMultiSendFunction -} from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/MultiSendBaseContract' // Remove all nested `readonly` modifiers from the ABI type type MultiSendContract_v1_1_1_Abi = DeepWriteable @@ -49,17 +45,6 @@ class MultiSendContract_v1_1_1_Web3 this.safeVersion = safeVersion } - - getAddress: GetAddressMultiSendFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - encode: EncodeMultiSendFunction = ( - functionToEncode, - args - ) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } } export default MultiSendContract_v1_1_1_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Web3.ts index 5e2718251..8fb7a51ad 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Web3.ts @@ -6,10 +6,6 @@ import MultiSendCallOnlyContract_v1_3_0_Contract, { } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.3.0/MultiSendCallOnlyContract_v1_3_0' import multiSend_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/MultiSend/v1.3.0/multi_send_call_only' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeMultiSendCallOnlyFunction, - GetAddressMultiSendCallOnlyFunction -} from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/MultiSendCallOnlyBaseContract' // Remove all nested `readonly` modifiers from the ABI type type MultiSendCallOnlyContract_v1_3_0_Abi = @@ -50,17 +46,6 @@ class MultiSendCallOnlyContract_v1_3_0_Web3 this.safeVersion = safeVersion } - - getAddress: GetAddressMultiSendCallOnlyFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - encode: EncodeMultiSendCallOnlyFunction = ( - functionToEncode, - args - ) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } } export default MultiSendCallOnlyContract_v1_3_0_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.3.0/MultiSendContract_V1_3_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.3.0/MultiSendContract_V1_3_0_Web3.ts index 5c5966d41..d7716ede6 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.3.0/MultiSendContract_V1_3_0_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.3.0/MultiSendContract_V1_3_0_Web3.ts @@ -6,10 +6,6 @@ import MultiSendContract_v1_3_0_Contract, { } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.3.0/MultiSendContract_v1_3_0' import multiSend_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/MultiSend/v1.3.0/multi_send' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeMultiSendFunction, - GetAddressMultiSendFunction -} from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/MultiSendBaseContract' // Remove all nested `readonly` modifiers from the ABI type type MultiSendContract_v1_3_0_Abi = DeepWriteable @@ -49,17 +45,6 @@ class MultiSendContract_v1_3_0_Web3 this.safeVersion = safeVersion } - - getAddress: GetAddressMultiSendFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - encode: EncodeMultiSendFunction = ( - functionToEncode, - args - ) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } } export default MultiSendContract_v1_3_0_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Web3.ts index 6af6b3e27..d38f19d44 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Web3.ts @@ -6,10 +6,6 @@ import MultiSendCallOnlyContract_v1_4_1_Contract, { } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.4.1/MultiSendCallOnlyContract_v1_4_1' import multiSend_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/MultiSend/v1.4.1/multi_send_call_only' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeMultiSendCallOnlyFunction, - GetAddressMultiSendCallOnlyFunction -} from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/MultiSendCallOnlyBaseContract' // Remove all nested `readonly` modifiers from the ABI type type MultiSendCallOnlyContract_v1_4_1_Abi = @@ -50,17 +46,6 @@ class MultiSendCallOnlyContract_v1_4_1_Web3 this.safeVersion = safeVersion } - - getAddress: GetAddressMultiSendCallOnlyFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - encode: EncodeMultiSendCallOnlyFunction = ( - functionToEncode, - args - ) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } } export default MultiSendCallOnlyContract_v1_4_1_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.4.1/MultiSendContract_V1_4_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.4.1/MultiSendContract_V1_4_1_Web3.ts index f6db61407..732657d1d 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.4.1/MultiSendContract_V1_4_1_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/MultiSend/v1.4.1/MultiSendContract_V1_4_1_Web3.ts @@ -6,10 +6,6 @@ import MultiSendContract_v1_4_1_Contract, { } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.4.1/MultiSendContract_v1_4_1' import multiSend_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/MultiSend/v1.4.1/multi_send' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeMultiSendFunction, - GetAddressMultiSendFunction -} from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/MultiSendBaseContract' // Remove all nested `readonly` modifiers from the ABI type type MultiSendContract_v1_4_1_Abi = DeepWriteable @@ -49,17 +45,6 @@ class MultiSendContract_v1_4_1_Web3 this.safeVersion = safeVersion } - - getAddress: GetAddressMultiSendFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - encode: EncodeMultiSendFunction = ( - functionToEncode, - args - ) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } } export default MultiSendContract_v1_4_1_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/Safe/SafeBaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/Safe/SafeBaseContractWeb3.ts index bcd8c8853..e7f4b6168 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/Safe/SafeBaseContractWeb3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/Safe/SafeBaseContractWeb3.ts @@ -1,20 +1,19 @@ -import Contract from 'web3-eth-contract' +import { Abi } from 'abitype' import { AbiItem } from 'web3-utils' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import SafeBaseContract from '@safe-global/protocol-kit/adapters/SafeBaseContract' +import BaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/BaseContractWeb3' +import { contractName, safeDeploymentsL1ChainIds } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class SafeBaseContractWeb3 extends SafeBaseContract to specifically integrate with the Web3.js library. + * Abstract class SafeBaseContractWeb3 extends BaseContractWeb3 to specifically integrate with the Safe contract. * 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 contract version. - * * Subclasses of SafeBaseContractWeb3 are expected to represent specific versions of the Safe contract. * * @template SafeContractAbiType - The ABI type specific to the version of the Safe contract, extending AbiItem. - * @extends SafeBaseContract - Extends the generic SafeBaseContract with Web3-specific implementation. + * @extends BaseContractWeb3 - Extends the generic BaseContractWeb3. * * Example subclasses: * - SafeContract_v1_4_1_Web3 extends SafeBaseContractWeb3 @@ -24,10 +23,9 @@ import SafeBaseContract from '@safe-global/protocol-kit/adapters/SafeBaseContrac * - SafeContract_v1_0_0_Web3 extends SafeBaseContractWeb3 */ abstract class SafeBaseContractWeb3< - SafeContractAbiType extends AbiItem[] -> extends SafeBaseContract { - contract: Contract - adapter: Web3Adapter + SafeContractAbiType extends AbiItem[] & Abi +> extends BaseContractWeb3 { + contractName: contractName /** * @constructor @@ -50,17 +48,20 @@ abstract class SafeBaseContractWeb3< customContractAddress?: string, customContractAbi?: SafeContractAbiType ) { + const isL1Contract = safeDeploymentsL1ChainIds.includes(chainId) || isL1SafeSingleton + const contractName = isL1Contract ? 'safeSingletonVersion' : 'safeSingletonL2Version' + super( + contractName, chainId, + web3Adapter, defaultAbi, safeVersion, - isL1SafeSingleton, customContractAddress, customContractAbi ) - this.adapter = web3Adapter - this.contract = web3Adapter.getContract(this.contractAddress, this.contractAbi) + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.0.0/SafeContract_v1_0_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.0.0/SafeContract_v1_0_0_Web3.ts index a58e556b6..ae7f38d7d 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.0.0/SafeContract_v1_0_0_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.0.0/SafeContract_v1_0_0_Web3.ts @@ -7,12 +7,9 @@ import { import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import safe_1_0_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.0.0/gnosis_safe' -import { - EncodeSafeFunction, - EstimateGasSafeFunction -} from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' import SafeContract_v1_0_0_Contract, { - SafeContract_v1_0_0_Abi as SafeContract_v1_0_0_Abi_Readonly + SafeContract_v1_0_0_Abi as SafeContract_v1_0_0_Abi_Readonly, + SafeContract_v1_0_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.0.0/SafeContract_v1_0_0' import { sameString } from '@safe-global/protocol-kit/utils' import { SafeTransaction, SafeTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -67,125 +64,156 @@ class SafeContract_v1_0_0_Web3 } /* ----- Specific v1.0.0 properties ----- */ - async DOMAIN_SEPARATOR_TYPEHASH(): Promise<[string]> { - return [await this.contract.methods.DOMAIN_SEPARATOR_TYPEHASH().call()] - } + DOMAIN_SEPARATOR_TYPEHASH: SafeContract_v1_0_0_Function<'DOMAIN_SEPARATOR_TYPEHASH'> = + async () => { + return [await this.contract.methods.DOMAIN_SEPARATOR_TYPEHASH().call()] + } - async SENTINEL_MODULES(): Promise<[string]> { + SENTINEL_MODULES: SafeContract_v1_0_0_Function<'SENTINEL_MODULES'> = async () => { return [await this.contract.methods.SENTINEL_MODULES().call()] } - async SENTINEL_OWNERS(): Promise<[string]> { + SENTINEL_OWNERS: SafeContract_v1_0_0_Function<'SENTINEL_OWNERS'> = async () => { return [await this.contract.methods.SENTINEL_OWNERS().call()] } - async SAFE_MSG_TYPEHASH(): Promise<[string]> { + SAFE_MSG_TYPEHASH: SafeContract_v1_0_0_Function<'SAFE_MSG_TYPEHASH'> = async () => { return [await this.contract.methods.SAFE_MSG_TYPEHASH().call()] } - async SAFE_TX_TYPEHASH(): Promise<[string]> { + SAFE_TX_TYPEHASH: SafeContract_v1_0_0_Function<'SAFE_TX_TYPEHASH'> = async () => { return [await this.contract.methods.SAFE_TX_TYPEHASH().call()] } /* ----- End of specific v1.0.0 properties ----- */ - async NAME(): Promise<[string]> { + /** + * @returns Array[contractName] + */ + NAME: SafeContract_v1_0_0_Function<'NAME'> = async () => { return [await this.contract.methods.NAME().call()] } - async VERSION(): Promise<[SafeVersion]> { + /** + * @returns Array[safeContractVersion] + */ + VERSION: SafeContract_v1_0_0_Function<'VERSION'> = async () => { return [await this.contract.methods.VERSION().call()] } - async approvedHashes(args: readonly [owner: string, txHash: string]): Promise<[bigint]> { + /** + * @param args - Array[owner, txHash] + * @returns Array[approvedHashes] + */ + approvedHashes: SafeContract_v1_0_0_Function<'approvedHashes'> = async (args) => { return [await this.contract.methods.approvedHashes(...args).call()] } - async domainSeparator(): Promise<[string]> { + /** + * @returns Array[domainSeparator] + */ + domainSeparator: SafeContract_v1_0_0_Function<'domainSeparator'> = async () => { return [await this.contract.methods.domainSeparator().call()] } - async getModules(): Promise<[string[]]> { + /** + * Returns array of modules. + * @returns Array[Array[modules]] + */ + getModules: SafeContract_v1_0_0_Function<'getModules'> = async () => { return [await this.contract.methods.getModules().call()] } - async getOwners(): Promise { + /** + * Returns the list of Safe owner accounts. + * @returns Array[Array[owners]] + */ + getOwners: SafeContract_v1_0_0_Function<'getOwners'> = async () => { return [await this.contract.methods.getOwners().call()] } - async getThreshold(): Promise<[bigint]> { + /** + * Returns the Safe threshold. + * @returns Array[threshold] + */ + getThreshold: SafeContract_v1_0_0_Function<'getThreshold'> = async () => { return [await this.contract.methods.getThreshold().call()] } - async isOwner(args: readonly [address: string]): Promise<[boolean]> { + /** + * Checks if a specific address is an owner of the current Safe. + * @param args - Array[address] + * @returns Array[isOwner] + */ + isOwner: SafeContract_v1_0_0_Function<'isOwner'> = async (args) => { return [await this.contract.methods.isOwner(...args).call()] } - async nonce(): Promise<[bigint]> { + /** + * Returns the Safe nonce. + * @returns Array[nonce] + */ + nonce: SafeContract_v1_0_0_Function<'nonce'> = async () => { return [await this.contract.methods.nonce().call()] } - async signedMessages(args: readonly [messageHash: string]): Promise<[bigint]> { + /** + * @param args - Array[messageHash] + * @returns Array[signedMessages] + */ + signedMessages: SafeContract_v1_0_0_Function<'signedMessages'> = async (args) => { return [await this.contract.methods.signedMessages(...args).call()] } - async getMessageHash(args: readonly [message: string]): Promise<[string]> { + /** + * Returns hash of a message that can be signed by owners. + * @param args - Array[message] + * @returns Array[messageHash] + */ + getMessageHash: SafeContract_v1_0_0_Function<'getMessageHash'> = async (args) => { return [await this.contract.methods.getMessageHash(...args).call()] } - async encodeTransactionData( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns the bytes that are hashed to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[encodedData] + */ + encodeTransactionData: SafeContract_v1_0_0_Function<'encodeTransactionData'> = async (args) => { return [await this.contract.methods.encodeTransactionData(...args).call()] } - async getTransactionHash( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns hash to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[transactionHash] + */ + getTransactionHash: SafeContract_v1_0_0_Function<'getTransactionHash'> = async (args) => { return [await this.contract.methods.getTransactionHash(...args).call()] } - encode: EncodeSafeFunction = (functionToEncode, args) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - estimateGas: EstimateGasSafeFunction = ( - functionToEstimate, - args, - options = {} - ) => { - return this.contract.methods[functionToEstimate](...args) - .estimateGas(options) - .then(BigInt) - } - - // Custom method (not defined in the Safe Contract) - getAddress(): Promise { - return Promise.resolve(this.contract.options.address) + /** + * Marks a hash as approved. This can be used to validate a hash that is used by a signature. + * @param hash - The hash that should be marked as approved for signatures that are verified by this contract. + * @param options - Optional transaction options. + * @returns Transaction result. + */ + async approveHash( + hash: string, + options?: Web3TransactionOptions + ): Promise { + if (options && !options.gas) { + options.gas = (await this.estimateGas('approveHash', [hash], { ...options })).toString() + } + const txResponse = this.contract.methods.approveHash(hash).send(options) + return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) + /** + * Executes a transaction. + * @param safeTransaction - The Safe transaction to execute. + * @param options - Transaction options. + * @returns Transaction result. + */ async execTransaction( safeTransaction: SafeTransaction, options?: Web3TransactionOptions @@ -228,7 +256,11 @@ class SafeContract_v1_0_0_Web3 return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) + /** + * Checks if a specific Safe module is enabled for the current Safe. + * @param moduleAddress - The module address to check. + * @returns True, if the module with the given address is enabled. + */ async isModuleEnabled(moduleAddress: string): Promise { const [modules] = await this.getModules() const isModuleEnabled = modules.some((enabledModuleAddress: string) => @@ -237,7 +269,12 @@ class SafeContract_v1_0_0_Web3 return isModuleEnabled } - // Custom method (not defined in the Safe Contract) + /** + * Checks whether a given Safe transaction can be executed successfully with no errors. + * @param safeTransaction - The Safe transaction to check. + * @param options - Optional transaction options. + * @returns True, if the given transactions is valid. + */ async isValidTransaction( safeTransaction: SafeTransaction, options?: Web3TransactionOptions @@ -282,18 +319,6 @@ class SafeContract_v1_0_0_Web3 return isTxValid } - // Custom method (not defined in the Safe Contract) - async approveHash( - hash: string, - options?: Web3TransactionOptions - ): Promise { - if (options && !options.gas) { - options.gas = (await this.estimateGas('approveHash', [hash], { ...options })).toString() - } - const txResponse = this.contract.methods.approveHash(hash).send(options) - return toTxResult(txResponse, options) - } - // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): any { return { diff --git a/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.1.1/SafeContract_v1_1_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.1.1/SafeContract_v1_1_1_Web3.ts index 0a8832396..48857dd1a 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.1.1/SafeContract_v1_1_1_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.1.1/SafeContract_v1_1_1_Web3.ts @@ -7,12 +7,9 @@ import { import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import safe_1_1_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.1.1/gnosis_safe' -import { - EncodeSafeFunction, - EstimateGasSafeFunction -} from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' import SafeContract_v1_1_1_Contract, { - SafeContract_v1_1_1_Abi as SafeContract_v1_1_1_Abi_Readonly + SafeContract_v1_1_1_Abi as SafeContract_v1_1_1_Abi_Readonly, + SafeContract_v1_1_1_Function } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.1.1/SafeContract_v1_1_1' import { sameString } from '@safe-global/protocol-kit/utils' import { SafeTransaction, SafeTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -66,111 +63,144 @@ class SafeContract_v1_1_1_Web3 this.safeVersion = safeVersion } - async NAME(): Promise<[string]> { + /** + * @returns Array[contractName] + */ + NAME: SafeContract_v1_1_1_Function<'NAME'> = async () => { return [await this.contract.methods.NAME().call()] } - async VERSION(): Promise<[SafeVersion]> { + /** + * @returns Array[safeContractVersion] + */ + VERSION: SafeContract_v1_1_1_Function<'VERSION'> = async () => { return [await this.contract.methods.VERSION().call()] } - async approvedHashes(args: readonly [owner: string, txHash: string]): Promise<[bigint]> { + /** + * @param args - Array[owner, txHash] + * @returns Array[approvedHashes] + */ + approvedHashes: SafeContract_v1_1_1_Function<'approvedHashes'> = async (args) => { return [await this.contract.methods.approvedHashes(...args).call()] } - async domainSeparator(): Promise<[string]> { + /** + * @returns Array[domainSeparator] + */ + domainSeparator: SafeContract_v1_1_1_Function<'domainSeparator'> = async () => { return [await this.contract.methods.domainSeparator().call()] } - async getModules(): Promise<[string[]]> { + /** + * Returns array of first 10 modules. + * @returns Array[Array[modules]] + */ + getModules: SafeContract_v1_1_1_Function<'getModules'> = async () => { return [await this.contract.methods.getModules().call()] } - async getModulesPaginated( - args: readonly [start: string, pageSize: bigint] - ): Promise<[modules: string[], next: string]> { + /** + * Returns array of modules. + * @param args - Array[start, pageSize] + * @returns Array[Array[modules], next] + */ + getModulesPaginated: SafeContract_v1_1_1_Function<'getModulesPaginated'> = async (args) => { const res = await this.contract.methods.getModulesPaginated(...args).call() return [res.array, res.next] } - async getOwners(): Promise { + /** + * Returns the list of Safe owner accounts. + * @returns Array[Array[owners]] + */ + getOwners: SafeContract_v1_1_1_Function<'getOwners'> = async () => { return [await this.contract.methods.getOwners().call()] } - async getThreshold(): Promise<[bigint]> { + /** + * Returns the Safe threshold. + * @returns Array[threshold] + */ + getThreshold: SafeContract_v1_1_1_Function<'getThreshold'> = async () => { return [await this.contract.methods.getThreshold().call()] } - async isOwner(args: readonly [address: string]): Promise<[boolean]> { + /** + * Checks if a specific address is an owner of the current Safe. + * @param args - Array[address] + * @returns Array[isOwner] + */ + isOwner: SafeContract_v1_1_1_Function<'isOwner'> = async (args) => { return [await this.contract.methods.isOwner(...args).call()] } - async nonce(): Promise<[bigint]> { + /** + * Returns the Safe nonce. + * @returns Array[nonce] + */ + nonce: SafeContract_v1_1_1_Function<'nonce'> = async () => { return [await this.contract.methods.nonce().call()] } - async signedMessages(args: readonly [messageHash: string]): Promise<[bigint]> { + /** + * @param args - Array[messageHash] + * @returns Array[signedMessages] + */ + signedMessages: SafeContract_v1_1_1_Function<'signedMessages'> = async (args) => { return [await this.contract.methods.signedMessages(...args).call()] } - async getMessageHash(args: readonly [message: string]): Promise<[string]> { + /** + * Returns hash of a message that can be signed by owners. + * @param args - Array[message] + * @returns Array[messageHash] + */ + getMessageHash: SafeContract_v1_1_1_Function<'getMessageHash'> = async (args) => { return [await this.contract.methods.getMessageHash(...args).call()] } - async encodeTransactionData( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns the bytes that are hashed to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[encodedData] + */ + encodeTransactionData: SafeContract_v1_1_1_Function<'encodeTransactionData'> = async (args) => { return [await this.contract.methods.encodeTransactionData(...args).call()] } - async getTransactionHash( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns hash to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[transactionHash] + */ + getTransactionHash: SafeContract_v1_1_1_Function<'getTransactionHash'> = async (args) => { return [await this.contract.methods.getTransactionHash(...args).call()] } - encode: EncodeSafeFunction = (functionToEncode, args) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - estimateGas: EstimateGasSafeFunction = ( - functionToEstimate, - args, - options = {} - ) => { - return this.contract.methods[functionToEstimate](...args) - .estimateGas(options) - .then(BigInt) - } - - // Custom method (not defined in the Safe Contract) - getAddress(): Promise { - return Promise.resolve(this.contract.options.address) + /** + * Marks a hash as approved. This can be used to validate a hash that is used by a signature. + * @param hash - The hash that should be marked as approved for signatures that are verified by this contract. + * @param options - Optional transaction options. + * @returns Transaction result. + */ + async approveHash( + hash: string, + options?: Web3TransactionOptions + ): Promise { + if (options && !options.gas) { + options.gas = (await this.estimateGas('approveHash', [hash], { ...options })).toString() + } + const txResponse = this.contract.methods.approveHash(hash).send(options) + return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) + /** + * Executes a transaction. + * @param safeTransaction - The Safe transaction to execute. + * @param options - Transaction options. + * @returns Transaction result. + */ async execTransaction( safeTransaction: SafeTransaction, options?: Web3TransactionOptions @@ -213,7 +243,11 @@ class SafeContract_v1_1_1_Web3 return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) + /** + * Checks if a specific Safe module is enabled for the current Safe. + * @param moduleAddress - The module address to check. + * @returns True, if the module with the given address is enabled. + */ async isModuleEnabled(moduleAddress: string): Promise { const [modules] = await this.getModules() const isModuleEnabled = modules.some((enabledModuleAddress: string) => @@ -222,7 +256,12 @@ class SafeContract_v1_1_1_Web3 return isModuleEnabled } - // Custom method (not defined in the Safe Contract) + /** + * Checks whether a given Safe transaction can be executed successfully with no errors. + * @param safeTransaction - The Safe transaction to check. + * @param options - Optional transaction options. + * @returns True, if the given transactions is valid. + */ async isValidTransaction( safeTransaction: SafeTransaction, options?: Web3TransactionOptions @@ -267,18 +306,6 @@ class SafeContract_v1_1_1_Web3 return isTxValid } - // Custom method (not defined in the Safe Contract) - async approveHash( - hash: string, - options?: Web3TransactionOptions - ): Promise { - if (options && !options.gas) { - options.gas = (await this.estimateGas('approveHash', [hash], { ...options })).toString() - } - const txResponse = this.contract.methods.approveHash(hash).send(options) - return toTxResult(txResponse, options) - } - // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): any { return { diff --git a/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.2.0/SafeContract_v1_2_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.2.0/SafeContract_v1_2_0_Web3.ts index 5ea57fb34..4e9d86133 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.2.0/SafeContract_v1_2_0_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.2.0/SafeContract_v1_2_0_Web3.ts @@ -7,12 +7,9 @@ import { import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import safe_1_2_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.2.0/gnosis_safe' -import { - EncodeSafeFunction, - EstimateGasSafeFunction -} from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' import SafeContract_v1_2_0_Contract, { - SafeContract_v1_2_0_Abi as SafeContract_v1_2_0_Abi_Readonly + SafeContract_v1_2_0_Abi as SafeContract_v1_2_0_Abi_Readonly, + SafeContract_v1_2_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.2.0/SafeContract_v1_2_0' import { SafeTransaction, SafeTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -65,115 +62,154 @@ class SafeContract_v1_2_0_Web3 this.safeVersion = safeVersion } - async NAME(): Promise<[string]> { + /** + * @returns Array[contractName] + */ + NAME: SafeContract_v1_2_0_Function<'NAME'> = async () => { return [await this.contract.methods.NAME().call()] } - async VERSION(): Promise<[SafeVersion]> { + /** + * @returns Array[safeContractVersion] + */ + VERSION: SafeContract_v1_2_0_Function<'VERSION'> = async () => { return [await this.contract.methods.VERSION().call()] } - async approvedHashes(args: readonly [owner: string, txHash: string]): Promise<[bigint]> { + /** + * @param args - Array[owner, txHash] + * @returns Array[approvedHashes] + */ + approvedHashes: SafeContract_v1_2_0_Function<'approvedHashes'> = async (args) => { return [await this.contract.methods.approvedHashes(...args).call()] } - async domainSeparator(): Promise<[string]> { + /** + * @returns Array[domainSeparator] + */ + domainSeparator: SafeContract_v1_2_0_Function<'domainSeparator'> = async () => { return [await this.contract.methods.domainSeparator().call()] } - async getModules(): Promise<[string[]]> { + /** + * Returns array of first 10 modules. + * @returns Array[Array[modules]] + */ + getModules: SafeContract_v1_2_0_Function<'getModules'> = async () => { return [await this.contract.methods.getModules().call()] } - async getModulesPaginated( - args: readonly [start: string, pageSize: bigint] - ): Promise<[modules: string[], next: string]> { + /** + * Returns array of modules. + * @param args - Array[start, pageSize] + * @returns Array[Array[modules], next] + */ + getModulesPaginated: SafeContract_v1_2_0_Function<'getModulesPaginated'> = async (args) => { const res = await this.contract.methods.getModulesPaginated(...args).call() return [res.array, res.next] } - async getOwners(): Promise { + /** + * Returns the list of Safe owner accounts. + * @returns Array[Array[owners]] + */ + getOwners: SafeContract_v1_2_0_Function<'getOwners'> = async () => { return [await this.contract.methods.getOwners().call()] } - async getThreshold(): Promise<[bigint]> { + /** + * Returns the Safe threshold. + * @returns Array[threshold] + */ + getThreshold: SafeContract_v1_2_0_Function<'getThreshold'> = async () => { return [await this.contract.methods.getThreshold().call()] } - async isModuleEnabled(args: readonly [moduleAddress: string]): Promise<[boolean]> { + /** + * Checks if a specific Safe module is enabled for the current Safe. + * @param args - Array[moduleAddress] + * @returns Array[isEnabled] + */ + isModuleEnabled: SafeContract_v1_2_0_Function<'isModuleEnabled'> = async (args) => { return [await this.contract.methods.isModuleEnabled(...args).call()] } - async isOwner(args: readonly [address: string]): Promise<[boolean]> { + /** + * Checks if a specific address is an owner of the current Safe. + * @param args - Array[address] + * @returns Array[isOwner] + */ + isOwner: SafeContract_v1_2_0_Function<'isOwner'> = async (args) => { return [await this.contract.methods.isOwner(...args).call()] } - async nonce(): Promise<[bigint]> { + /** + * Returns the Safe nonce. + * @returns Array[nonce] + */ + nonce: SafeContract_v1_2_0_Function<'nonce'> = async () => { return [await this.contract.methods.nonce().call()] } - async signedMessages(args: readonly [messageHash: string]): Promise<[bigint]> { + /** + * @param args - Array[messageHash] + * @returns Array[signedMessages] + */ + signedMessages: SafeContract_v1_2_0_Function<'signedMessages'> = async (args) => { return [await this.contract.methods.signedMessages(...args).call()] } - async getMessageHash(args: readonly [message: string]): Promise<[string]> { + /** + * @param args - Array[message] + * @returns Array[messageHash] + */ + getMessageHash: SafeContract_v1_2_0_Function<'getMessageHash'> = async (args) => { return [await this.contract.methods.getMessageHash(...args).call()] } - async encodeTransactionData( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Encodes the data for a transaction to the Safe contract. + * + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[encodedData] + */ + encodeTransactionData: SafeContract_v1_2_0_Function<'encodeTransactionData'> = async (args) => { return [await this.contract.methods.encodeTransactionData(...args).call()] } - async getTransactionHash( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns hash to be signed by owners. + * + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[transactionHash] + */ + getTransactionHash: SafeContract_v1_2_0_Function<'getTransactionHash'> = async (args) => { return [await this.contract.methods.getTransactionHash(...args).call()] } - encode: EncodeSafeFunction = (functionToEncode, args) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - estimateGas: EstimateGasSafeFunction = ( - functionToEstimate, - args, - options = {} - ) => { - return this.contract.methods[functionToEstimate](...args) - .estimateGas(options) - .then(BigInt) - } - - // Custom method (not defined in the Safe Contract) - getAddress(): Promise { - return Promise.resolve(this.contract.options.address) + /** + * Marks a hash as approved. This can be used to validate a hash that is used by a signature. + * @param hash - The hash that should be marked as approved for signatures that are verified by this contract. + * @param options - Optional transaction options. + * @returns Transaction result. + */ + async approveHash( + hash: string, + options?: Web3TransactionOptions + ): Promise { + if (options && !options.gas) { + options.gas = (await this.estimateGas('approveHash', [hash], { ...options })).toString() + } + const txResponse = this.contract.methods.approveHash(hash).send(options) + return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) + /** + * Executes a transaction. + * @param safeTransaction - The Safe transaction to execute. + * @param options - Transaction options. + * @returns Transaction result. + */ async execTransaction( safeTransaction: SafeTransaction, options?: Web3TransactionOptions @@ -216,7 +252,12 @@ class SafeContract_v1_2_0_Web3 return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) + /** + * Checks whether a given Safe transaction can be executed successfully with no errors. + * @param safeTransaction - The Safe transaction to check. + * @param options - Optional transaction options. + * @returns True, if the given transactions is valid. + */ async isValidTransaction( safeTransaction: SafeTransaction, options?: Web3TransactionOptions @@ -261,18 +302,6 @@ class SafeContract_v1_2_0_Web3 return isTxValid } - // Custom method (not defined in the Safe Contract) - async approveHash( - hash: string, - options?: Web3TransactionOptions - ): Promise { - if (options && !options.gas) { - options.gas = (await this.estimateGas('approveHash', [hash], { ...options })).toString() - } - const txResponse = this.contract.methods.approveHash(hash).send(options) - return toTxResult(txResponse, options) - } - // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): any { return { diff --git a/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Web3.ts index 7de3153f0..aa73e2cd3 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.3.0/SafeContract_v1_3_0_Web3.ts @@ -8,12 +8,9 @@ import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' import { SENTINEL_ADDRESS } from '@safe-global/protocol-kit/adapters/web3/utils/constants' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import safe_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.3.0/gnosis_safe_l2' -import { - EncodeSafeFunction, - EstimateGasSafeFunction -} from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' import SafeContract_v1_3_0_Contract, { - SafeContract_v1_3_0_Abi as SafeContract_v1_3_0_Abi_Readonly + SafeContract_v1_3_0_Abi as SafeContract_v1_3_0_Abi_Readonly, + SafeContract_v1_3_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.3.0/SafeContract_v1_3_0' import { SafeTransaction, SafeTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -66,134 +63,194 @@ class SafeContract_v1_3_0_Web3 this.safeVersion = safeVersion } - async VERSION(): Promise<[SafeVersion]> { + /** + * @returns Array[safeContractVersion] + */ + VERSION: SafeContract_v1_3_0_Function<'VERSION'> = async () => { return [await this.contract.methods.VERSION().call()] } - async approvedHashes(args: readonly [owner: string, txHash: string]): Promise<[bigint]> { + /** + * @param args - Array[owner, txHash] + * @returns Array[approvedHashes] + */ + approvedHashes: SafeContract_v1_3_0_Function<'approvedHashes'> = async (args) => { return [await this.contract.methods.approvedHashes(...args).call()] } - async checkNSignatures( - args: readonly [dataHash: string, data: string, signatures: string, requiredSignatures: bigint] - ): Promise<[]> { - // this method just checks whether the signature provided is valid for the provided data and hash. Reverts otherwise. + /** + * Checks whether the signature provided is valid for the provided data, hash and number of required signatures. + * Will revert otherwise. + * @param args - Array[dataHash, data, signatures, requiredSignatures] + * @returns Empty array + */ + checkNSignatures: SafeContract_v1_3_0_Function<'checkNSignatures'> = async (args) => { if (this.contract.methods.checkNSignatures) { await this.contract.methods.checkNSignatures(...args).call() } return [] } - async checkSignatures( - args: readonly [dataHash: string, data: string, signatures: string] - ): Promise<[]> { + /** + * Checks whether the signature provided is valid for the provided data and hash. Will revert otherwise. + * @param args - Array[dataHash, data, signatures] + * @returns Empty array + */ + checkSignatures: SafeContract_v1_3_0_Function<'checkSignatures'> = async (args) => { await this.contract.methods.checkSignatures(...args).call() return [] } - async domainSeparator(): Promise<[string]> { + /** + * @returns Array[domainSeparator] + */ + domainSeparator: SafeContract_v1_3_0_Function<'domainSeparator'> = async () => { return [await this.contract.methods.domainSeparator().call()] } - async encodeTransactionData( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Encodes the data for a transaction to the Safe contract. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[encodedData] + */ + encodeTransactionData: SafeContract_v1_3_0_Function<'encodeTransactionData'> = async (args) => { return [await this.contract.methods.encodeTransactionData(...args).call()] } - async getChainId(): Promise<[bigint]> { - return [await this.contract.methods.getChainId().call()] - } - - async getModulesPaginated( - args: readonly [start: string, pageSize: bigint] - ): Promise<[modules: string[], next: string]> { + /** + * Returns array of modules. + * @param args - Array[start, pageSize] + * @returns Array[Array[modules], next] + */ + getModulesPaginated: SafeContract_v1_3_0_Function<'getModulesPaginated'> = async (args) => { const res = await this.contract.methods.getModulesPaginated(...args).call() return [res.array, res.next] } - async getOwners(): Promise { + /** + * Returns the list of Safe owner accounts. + * @returns Array[Array[owners]] + */ + getOwners: SafeContract_v1_3_0_Function<'getOwners'> = async () => { return [await this.contract.methods.getOwners().call()] } - async getStorageAt(args: readonly [offset: bigint, length: bigint]): Promise<[string]> { + /** + * Reads `length` bytes of storage in the currents contract + * @param args - Array[offset, length] + * @returns Array[storage] + */ + getStorageAt: SafeContract_v1_3_0_Function<'getStorageAt'> = async (args) => { return [await this.contract.methods.getStorageAt(...args).call()] } - async getThreshold(): Promise<[bigint]> { + /** + * Returns the Safe threshold. + * @returns Array[threshold] + */ + getThreshold: SafeContract_v1_3_0_Function<'getThreshold'> = async () => { return [await this.contract.methods.getThreshold().call()] } - async getTransactionHash( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns hash to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[transactionHash] + */ + getTransactionHash: SafeContract_v1_3_0_Function<'getTransactionHash'> = async (args) => { return [await this.contract.methods.getTransactionHash(...args).call()] } - async isModuleEnabled(args: readonly [moduleAddress: string]): Promise<[boolean]> { + /** + * Checks if a specific Safe module is enabled for the current Safe. + * @param args - Array[moduleAddress] + * @returns Array[isEnabled] + */ + isModuleEnabled: SafeContract_v1_3_0_Function<'isModuleEnabled'> = async (args) => { return [await this.contract.methods.isModuleEnabled(...args).call()] } - async isOwner(args: readonly [address: string]): Promise<[boolean]> { + /** + * Checks if a specific address is an owner of the current Safe. + * @param args - Array[address] + * @returns Array[isOwner] + */ + isOwner: SafeContract_v1_3_0_Function<'isOwner'> = async (args) => { return [await this.contract.methods.isOwner(...args).call()] } - async nonce(): Promise<[bigint]> { + /** + * Returns the Safe nonce. + * @returns Array[nonce] + */ + nonce: SafeContract_v1_3_0_Function<'nonce'> = async () => { return [await this.contract.methods.nonce().call()] } - async signedMessages(args: readonly [messageHash: string]): Promise<[bigint]> { + /** + * @param args - Array[messageHash] + * @returns Array[signedMessages] + */ + signedMessages: SafeContract_v1_3_0_Function<'signedMessages'> = async (args) => { return [await this.contract.methods.signedMessages(...args).call()] } - encode: EncodeSafeFunction = (functionToEncode, args) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - estimateGas: EstimateGasSafeFunction = ( - functionToEstimate, - args, - options = {} - ) => { - return this.contract.methods[functionToEstimate](...args) - .estimateGas(options) - .then(BigInt) - } - - // Custom method (not defined in the Safe Contract) - async getModules(): Promise { - const [modules] = await this.getModulesPaginated([SENTINEL_ADDRESS, BigInt(10)]) - return modules - } - - // Custom method (not defined in the Safe Contract) - getAddress(): Promise { - return Promise.resolve(this.contract.options.address) + /** + * Checks whether a given Safe transaction can be executed successfully with no errors. + * @param safeTransaction - The Safe transaction to check. + * @param options - Optional transaction options. + * @returns True, if the given transactions is valid. + */ + async isValidTransaction( + safeTransaction: SafeTransaction, + options?: Web3TransactionOptions + ): Promise { + let isTxValid = false + try { + if (options && !options.gas) { + options.gas = ( + await this.estimateGas( + 'execTransaction', + [ + safeTransaction.data.to, + BigInt(safeTransaction.data.value), + safeTransaction.data.data, + safeTransaction.data.operation, + BigInt(safeTransaction.data.safeTxGas), + BigInt(safeTransaction.data.baseGas), + BigInt(safeTransaction.data.gasPrice), + safeTransaction.data.gasToken, + safeTransaction.data.refundReceiver, + safeTransaction.encodedSignatures() + ], + options + ) + ).toString() + } + isTxValid = await this.contract.methods + .execTransaction( + safeTransaction.data.to, + BigInt(safeTransaction.data.value), + safeTransaction.data.data, + safeTransaction.data.operation, + BigInt(safeTransaction.data.safeTxGas), + BigInt(safeTransaction.data.baseGas), + BigInt(safeTransaction.data.gasPrice), + safeTransaction.data.gasToken, + safeTransaction.data.refundReceiver, + safeTransaction.encodedSignatures() + ) + .call(options) + } catch {} + return isTxValid } - // Custom method (not defined in the Safe Contract) + /** + * Executes a transaction. + * @param safeTransaction - The Safe transaction to execute. + * @param options - Transaction options. + * @returns Transaction result. + */ async execTransaction( safeTransaction: SafeTransaction, options?: Web3TransactionOptions @@ -236,52 +293,21 @@ class SafeContract_v1_3_0_Web3 return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) - async isValidTransaction( - safeTransaction: SafeTransaction, - options?: Web3TransactionOptions - ): Promise { - let isTxValid = false - try { - if (options && !options.gas) { - options.gas = ( - await this.estimateGas( - 'execTransaction', - [ - safeTransaction.data.to, - BigInt(safeTransaction.data.value), - safeTransaction.data.data, - safeTransaction.data.operation, - BigInt(safeTransaction.data.safeTxGas), - BigInt(safeTransaction.data.baseGas), - BigInt(safeTransaction.data.gasPrice), - safeTransaction.data.gasToken, - safeTransaction.data.refundReceiver, - safeTransaction.encodedSignatures() - ], - options - ) - ).toString() - } - isTxValid = await this.contract.methods - .execTransaction( - safeTransaction.data.to, - BigInt(safeTransaction.data.value), - safeTransaction.data.data, - safeTransaction.data.operation, - BigInt(safeTransaction.data.safeTxGas), - BigInt(safeTransaction.data.baseGas), - BigInt(safeTransaction.data.gasPrice), - safeTransaction.data.gasToken, - safeTransaction.data.refundReceiver, - safeTransaction.encodedSignatures() - ) - .call(options) - } catch {} - return isTxValid + /** + * Returns array of first 10 modules. + * @returns Array[modules] + */ + async getModules(): Promise { + const [modules] = await this.getModulesPaginated([SENTINEL_ADDRESS, BigInt(10)]) + return modules } - // Custom method (not defined in the Safe Contract) + /** + * Marks a hash as approved. This can be used to validate a hash that is used by a signature. + * @param hash - The hash that should be marked as approved for signatures that are verified by this contract. + * @param options - Optional transaction options. + * @returns Transaction result. + */ async approveHash( hash: string, options?: Web3TransactionOptions @@ -293,6 +319,14 @@ class SafeContract_v1_3_0_Web3 return toTxResult(txResponse, options) } + /** + * Returns the chain id of the Safe contract. (Custom method - not defined in the Safe Contract) + * @returns Array[chainId] + */ + async getChainId(): Promise<[bigint]> { + return [await this.contract.methods.getChainId().call()] + } + // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): any { return { diff --git a/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Web3.ts index 3568ab481..9cf148a61 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/Safe/v1.4.1/SafeContract_v1_4_1_Web3.ts @@ -8,12 +8,9 @@ import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' import { SENTINEL_ADDRESS } from '@safe-global/protocol-kit/adapters/web3/utils/constants' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import safe_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.4.1/safe_l2' -import { - EncodeSafeFunction, - EstimateGasSafeFunction -} from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' import SafeContract_v1_4_1_Contract, { - SafeContract_v1_4_1_Abi as SafeContract_v1_4_1_Abi_Readonly + SafeContract_v1_4_1_Abi as SafeContract_v1_4_1_Abi_Readonly, + SafeContract_v1_4_1_Function } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.4.1/SafeContract_v1_4_1' import { SafeTransaction, SafeTransactionData, SafeVersion } from '@safe-global/safe-core-sdk-types' @@ -66,134 +63,194 @@ class SafeContract_v1_4_1_Web3 this.safeVersion = safeVersion } - async VERSION(): Promise<[SafeVersion]> { + /** + * @returns Array[safeContractVersion] + */ + VERSION: SafeContract_v1_4_1_Function<'VERSION'> = async () => { return [await this.contract.methods.VERSION().call()] } - async approvedHashes(args: readonly [owner: string, txHash: string]): Promise<[bigint]> { + /** + * @param args - Array[owner, txHash] + * @returns Array[approvedHashes] + */ + approvedHashes: SafeContract_v1_4_1_Function<'approvedHashes'> = async (args) => { return [await this.contract.methods.approvedHashes(...args).call()] } - async checkNSignatures( - args: readonly [dataHash: string, data: string, signatures: string, requiredSignatures: bigint] - ): Promise<[]> { - // this method just checks whether the signature provided is valid for the provided data and hash. Reverts otherwise. + /** + * Checks whether the signature provided is valid for the provided data, hash and number of required signatures. + * Will revert otherwise. + * @param args - Array[dataHash, data, signatures, requiredSignatures] + * @returns Empty array + */ + checkNSignatures: SafeContract_v1_4_1_Function<'checkNSignatures'> = async (args) => { if (this.contract.methods.checkNSignatures) { await this.contract.methods.checkNSignatures(...args).call() } return [] } - async checkSignatures( - args: readonly [dataHash: string, data: string, signatures: string] - ): Promise<[]> { + /** + * Checks whether the signature provided is valid for the provided data and hash. Will revert otherwise. + * @param args - Array[dataHash, data, signatures] + * @returns Empty array + */ + checkSignatures: SafeContract_v1_4_1_Function<'checkSignatures'> = async (args) => { await this.contract.methods.checkSignatures(...args).call() return [] } - async domainSeparator(): Promise<[string]> { + /** + * @returns Array[domainSeparator] + */ + domainSeparator: SafeContract_v1_4_1_Function<'domainSeparator'> = async () => { return [await this.contract.methods.domainSeparator().call()] } - async encodeTransactionData( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Encodes the data for a transaction to the Safe contract. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[encodedData] + */ + encodeTransactionData: SafeContract_v1_4_1_Function<'encodeTransactionData'> = async (args) => { return [await this.contract.methods.encodeTransactionData(...args).call()] } - async getChainId(): Promise<[bigint]> { - return [await this.contract.methods.getChainId().call()] - } - - async getModulesPaginated( - args: readonly [start: string, pageSize: bigint] - ): Promise<[modules: string[], next: string]> { + /** + * Returns array of modules. + * @param args - Array[start, pageSize] + * @returns Array[Array[modules], next] + */ + getModulesPaginated: SafeContract_v1_4_1_Function<'getModulesPaginated'> = async (args) => { const res = await this.contract.methods.getModulesPaginated(...args).call() return [res.array, res.next] } - async getOwners(): Promise { + /** + * Returns the list of Safe owner accounts. + * @returns Array[Array[owners]] + */ + getOwners: SafeContract_v1_4_1_Function<'getOwners'> = async () => { return [await this.contract.methods.getOwners().call()] } - async getStorageAt(args: readonly [offset: bigint, length: bigint]): Promise<[string]> { + /** + * Reads `length` bytes of storage in the currents contract + * @param args - Array[offset, length] + * @returns Array[storage] + */ + getStorageAt: SafeContract_v1_4_1_Function<'getStorageAt'> = async (args) => { return [await this.contract.methods.getStorageAt(...args).call()] } - async getThreshold(): Promise<[bigint]> { + /** + * Returns the Safe threshold. + * @returns Array[threshold] + */ + getThreshold: SafeContract_v1_4_1_Function<'getThreshold'> = async () => { return [await this.contract.methods.getThreshold().call()] } - async getTransactionHash( - args: readonly [ - to: string, - value: bigint, - data: string, - operation: number, - safeTxGas: bigint, - baseGas: bigint, - gasPrice: bigint, - gasToken: string, - refundReceiver: string, - _nonce: bigint - ] - ): Promise<[string]> { + /** + * Returns hash to be signed by owners. + * @param args - Array[to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce] + * @returns Array[transactionHash] + */ + getTransactionHash: SafeContract_v1_4_1_Function<'getTransactionHash'> = async (args) => { return [await this.contract.methods.getTransactionHash(...args).call()] } - async isModuleEnabled(args: readonly [moduleAddress: string]): Promise<[boolean]> { + /** + * Checks if a specific Safe module is enabled for the current Safe. + * @param args - Array[moduleAddress] + * @returns Array[isEnabled] + */ + isModuleEnabled: SafeContract_v1_4_1_Function<'isModuleEnabled'> = async (args) => { return [await this.contract.methods.isModuleEnabled(...args).call()] } - async isOwner(args: readonly [address: string]): Promise<[boolean]> { + /** + * Checks if a specific address is an owner of the current Safe. + * @param args - Array[address] + * @returns Array[isOwner] + */ + isOwner: SafeContract_v1_4_1_Function<'isOwner'> = async (args) => { return [await this.contract.methods.isOwner(...args).call()] } - async nonce(): Promise<[bigint]> { + /** + * Returns the Safe nonce. + * @returns Array[nonce] + */ + nonce: SafeContract_v1_4_1_Function<'nonce'> = async () => { return [await this.contract.methods.nonce().call()] } - async signedMessages(args: readonly [messageHash: string]): Promise<[bigint]> { + /** + * @param args - Array[messageHash] + * @returns Array[signedMessages] + */ + signedMessages: SafeContract_v1_4_1_Function<'signedMessages'> = async (args) => { return [await this.contract.methods.signedMessages(...args).call()] } - encode: EncodeSafeFunction = (functionToEncode, args) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - estimateGas: EstimateGasSafeFunction = ( - functionToEstimate, - args, - options = {} - ) => { - return this.contract.methods[functionToEstimate](...args) - .estimateGas(options) - .then(BigInt) - } - - // Custom method (not defined in the Safe Contract) - async getModules(): Promise { - const [modules] = await this.getModulesPaginated([SENTINEL_ADDRESS, BigInt(10)]) - return modules - } - - // Custom method (not defined in the Safe Contract) - getAddress(): Promise { - return Promise.resolve(this.contract.options.address) + /** + * Checks whether a given Safe transaction can be executed successfully with no errors. + * @param safeTransaction - The Safe transaction to check. + * @param options - Optional transaction options. + * @returns True, if the given transactions is valid. + */ + async isValidTransaction( + safeTransaction: SafeTransaction, + options?: Web3TransactionOptions + ): Promise { + let isTxValid = false + try { + if (options && !options.gas) { + options.gas = ( + await this.estimateGas( + 'execTransaction', + [ + safeTransaction.data.to, + BigInt(safeTransaction.data.value), + safeTransaction.data.data, + safeTransaction.data.operation, + BigInt(safeTransaction.data.safeTxGas), + BigInt(safeTransaction.data.baseGas), + BigInt(safeTransaction.data.gasPrice), + safeTransaction.data.gasToken, + safeTransaction.data.refundReceiver, + safeTransaction.encodedSignatures() + ], + options + ) + ).toString() + } + isTxValid = await this.contract.methods + .execTransaction( + safeTransaction.data.to, + BigInt(safeTransaction.data.value), + safeTransaction.data.data, + safeTransaction.data.operation, + BigInt(safeTransaction.data.safeTxGas), + BigInt(safeTransaction.data.baseGas), + BigInt(safeTransaction.data.gasPrice), + safeTransaction.data.gasToken, + safeTransaction.data.refundReceiver, + safeTransaction.encodedSignatures() + ) + .call(options) + } catch {} + return isTxValid } - // Custom method (not defined in the Safe Contract) + /** + * Executes a transaction. + * @param safeTransaction - The Safe transaction to execute. + * @param options - Transaction options. + * @returns Transaction result. + */ async execTransaction( safeTransaction: SafeTransaction, options?: Web3TransactionOptions @@ -236,52 +293,21 @@ class SafeContract_v1_4_1_Web3 return toTxResult(txResponse, options) } - // Custom method (not defined in the Safe Contract) - async isValidTransaction( - safeTransaction: SafeTransaction, - options?: Web3TransactionOptions - ): Promise { - let isTxValid = false - try { - if (options && !options.gas) { - options.gas = ( - await this.estimateGas( - 'execTransaction', - [ - safeTransaction.data.to, - BigInt(safeTransaction.data.value), - safeTransaction.data.data, - safeTransaction.data.operation, - BigInt(safeTransaction.data.safeTxGas), - BigInt(safeTransaction.data.baseGas), - BigInt(safeTransaction.data.gasPrice), - safeTransaction.data.gasToken, - safeTransaction.data.refundReceiver, - safeTransaction.encodedSignatures() - ], - options - ) - ).toString() - } - isTxValid = await this.contract.methods - .execTransaction( - safeTransaction.data.to, - BigInt(safeTransaction.data.value), - safeTransaction.data.data, - safeTransaction.data.operation, - BigInt(safeTransaction.data.safeTxGas), - BigInt(safeTransaction.data.baseGas), - BigInt(safeTransaction.data.gasPrice), - safeTransaction.data.gasToken, - safeTransaction.data.refundReceiver, - safeTransaction.encodedSignatures() - ) - .call(options) - } catch {} - return isTxValid + /** + * Returns array of first 10 modules. + * @returns Array[modules] + */ + async getModules(): Promise { + const [modules] = await this.getModulesPaginated([SENTINEL_ADDRESS, BigInt(10)]) + return modules } - // Custom method (not defined in the Safe Contract) + /** + * Marks a hash as approved. This can be used to validate a hash that is used by a signature. + * @param hash - The hash that should be marked as approved for signatures that are verified by this contract. + * @param options - Optional transaction options. + * @returns Transaction result. + */ async approveHash( hash: string, options?: Web3TransactionOptions @@ -293,6 +319,14 @@ class SafeContract_v1_4_1_Web3 return toTxResult(txResponse, options) } + /** + * Returns the chain id of the Safe contract. (Custom method - not defined in the Safe Contract) + * @returns Array[chainId] + */ + async getChainId(): Promise<[bigint]> { + return [await this.contract.methods.getChainId().call()] + } + // TODO: Remove this mapper after remove Typechain mapToTypechainContract(): any { return { diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3.ts index 25ec95daf..c26be67ac 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3.ts @@ -1,20 +1,27 @@ -import Contract from 'web3-eth-contract' +import { Abi } from 'abitype' import { AbiItem } from 'web3-utils' +import { Web3TransactionOptions } from '@safe-global/protocol-kit/adapters/web3/types' 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' +import BaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/BaseContractWeb3' +import { contractName } from '@safe-global/protocol-kit/contracts/config' +import { + CreateProxyProps as CreateProxyPropsGeneral, + SafeVersion +} from '@safe-global/safe-core-sdk-types' + +export interface CreateProxyProps extends CreateProxyPropsGeneral { + options?: Web3TransactionOptions +} /** - * Abstract class SafeProxyFactoryBaseContractWeb3 extends SafeProxyFactoryBaseContract to specifically integrate with the Web3.js library. + * Abstract class SafeProxyFactoryBaseContractWeb3 extends BaseContractWeb3 to specifically integrate with the SafeProxyFactory contract. * 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. + * @extends BaseContractWeb3 - Extends the generic BaseContractWeb3. * * Example subclasses: * - SafeProxyFactoryContract_v1_4_1_Web3 extends SafeProxyFactoryBaseContractWeb3 @@ -24,10 +31,9 @@ import { SafeVersion } from '@safe-global/safe-core-sdk-types' * - SafeProxyFactoryContract_v1_0_0_Web3 extends SafeProxyFactoryBaseContractWeb3 */ abstract class SafeProxyFactoryBaseContractWeb3< - SafeProxyFactoryContractAbiType extends AbiItem[] -> extends SafeProxyFactoryBaseContract { - contract: Contract - adapter: Web3Adapter + SafeProxyFactoryContractAbiType extends AbiItem[] & Abi +> extends BaseContractWeb3 { + contractName: contractName /** * @constructor @@ -48,10 +54,19 @@ abstract class SafeProxyFactoryBaseContractWeb3< customContractAddress?: string, customContractAbi?: SafeProxyFactoryContractAbiType ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'safeProxyFactoryVersion' + + super( + contractName, + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi + ) - this.adapter = web3Adapter - this.contract = web3Adapter.getContract(this.contractAddress, this.contractAbi) + this.contractName = contractName } } 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 index 4f20af4d4..264c9cc7b 100644 --- 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 @@ -1,27 +1,20 @@ import { TransactionReceipt } from 'web3-core/types' -import SafeProxyFactoryBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3' +import SafeProxyFactoryBaseContractWeb3, { + CreateProxyProps +} 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 { DeepWriteable } 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 + SafeProxyFactoryContract_v1_0_0_Abi as SafeProxyFactoryContract_v1_0_0_Abi_Readonly, + SafeProxyFactoryContract_v1_0_0_Function } 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' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' -export interface CreateProxyProps extends CreateProxyPropsGeneral { - options?: Web3TransactionOptions -} +// Remove all nested `readonly` modifiers from the ABI type +type SafeProxyFactoryContract_v1_0_0_Abi = + DeepWriteable /** * SafeProxyFactoryContract_v1_0_0_Web3 is the implementation specific to the Safe Proxy Factory contract version 1.0.0. @@ -32,7 +25,7 @@ export interface CreateProxyProps extends CreateProxyPropsGeneral { * @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> + extends SafeProxyFactoryBaseContractWeb3 implements SafeProxyFactoryContract_v1_0_0_Contract { safeVersion: SafeVersion @@ -53,7 +46,7 @@ class SafeProxyFactoryContract_v1_0_0_Web3 ) { const safeVersion = '1.0.0' const defaultAbi = - safeProxyFactory_1_0_0_ContractArtifacts.abi as DeepWriteable + safeProxyFactory_1_0_0_ContractArtifacts.abi as SafeProxyFactoryContract_v1_0_0_Abi super( chainId, @@ -61,48 +54,53 @@ class SafeProxyFactoryContract_v1_0_0_Web3 defaultAbi, safeVersion, customContractAddress, - customContractAbi as DeepWriteable + customContractAbi as SafeProxyFactoryContract_v1_0_0_Abi ) 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]> { + /** + * Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address. + * @returns Array[creationCode] + */ + proxyCreationCode: SafeProxyFactoryContract_v1_0_0_Function<'proxyCreationCode'> = async () => { return [await this.contract.methods.proxyCreationCode().call()] } - async proxyRuntimeCode(): Promise<[string]> { + /** + * Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed. + * @returns Array[runtimeCode] + */ + proxyRuntimeCode: SafeProxyFactoryContract_v1_0_0_Function<'proxyRuntimeCode'> = async () => { return [await this.contract.methods.proxyRuntimeCode().call()] } - async createProxy(args: readonly [masterCopy: string, data: string]): Promise<[string]> { + /** + * Allows to create new proxy contact and execute a message call to the new proxy within one transaction. + * @param args - Array[masterCopy, data] + * @returns Array[proxyAddress] + */ + createProxy: SafeProxyFactoryContract_v1_0_0_Function<'createProxy'> = async (args) => { return [await this.contract.methods.createProxy(...args).call()] } - async createProxyWithNonce( - args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param args - Array[masterCopy, initializer, saltNonce] + * @returns Array[proxyAddress] + */ + createProxyWithNonce: SafeProxyFactoryContract_v1_0_0_Function<'createProxyWithNonce'> = async ( + args + ) => { return [await this.contract.methods.createProxyWithNonce(...args).call()] } + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param {CreateProxyProps} props - Properties for the new proxy contract. + * @returns The address of the new proxy contract. + */ async createProxyWithOptions({ safeSingletonAddress, initializer, 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 index dbfcb05d2..1785c4ae6 100644 --- 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 @@ -1,27 +1,20 @@ import { TransactionReceipt } from 'web3-core/types' -import SafeProxyFactoryBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3' +import SafeProxyFactoryBaseContractWeb3, { + CreateProxyProps +} 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 { DeepWriteable } 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 + SafeProxyFactoryContract_v1_1_1_Abi as SafeProxyFactoryContract_v1_1_1_Abi_Readonly, + SafeProxyFactoryContract_v1_1_1_Function } 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' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' -export interface CreateProxyProps extends CreateProxyPropsGeneral { - options?: Web3TransactionOptions -} +// Remove all nested `readonly` modifiers from the ABI type +type SafeProxyFactoryContract_v1_1_1_Abi = + DeepWriteable /** * SafeProxyFactoryContract_v1_1_1_Web3 is the implementation specific to the Safe Proxy Factory contract version 1.1.1. @@ -32,7 +25,7 @@ export interface CreateProxyProps extends CreateProxyPropsGeneral { * @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> + extends SafeProxyFactoryBaseContractWeb3 implements SafeProxyFactoryContract_v1_1_1_Contract { safeVersion: SafeVersion @@ -53,7 +46,7 @@ class SafeProxyFactoryContract_v1_1_1_Web3 ) { const safeVersion = '1.1.1' const defaultAbi = - safeProxyFactory_1_1_1_ContractArtifacts.abi as DeepWriteable + safeProxyFactory_1_1_1_ContractArtifacts.abi as SafeProxyFactoryContract_v1_1_1_Abi super( chainId, @@ -61,60 +54,73 @@ class SafeProxyFactoryContract_v1_1_1_Web3 defaultAbi, safeVersion, customContractAddress, - customContractAbi as DeepWriteable + customContractAbi as SafeProxyFactoryContract_v1_1_1_Abi ) 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]> { + /** + * Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address. + * @returns Array[creationCode] + */ + proxyCreationCode: SafeProxyFactoryContract_v1_1_1_Function<'proxyCreationCode'> = async () => { return [await this.contract.methods.proxyCreationCode().call()] } - async proxyRuntimeCode(): Promise<[string]> { + /** + * Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed. + * @returns Array[runtimeCode] + */ + proxyRuntimeCode: SafeProxyFactoryContract_v1_1_1_Function<'proxyRuntimeCode'> = async () => { 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()] - } + /** + * Allows to get the address for a new proxy contact created via `createProxyWithNonce`. + * @param args - Array[masterCopy, initializer, saltNonce] + * @returns Array[proxyAddress] + */ + calculateCreateProxyWithNonceAddress: SafeProxyFactoryContract_v1_1_1_Function<'calculateCreateProxyWithNonceAddress'> = + async (args) => { + return [await this.contract.methods.calculateCreateProxyWithNonceAddress(...args).call()] + } - async createProxy(args: readonly [masterCopy: string, data: string]): Promise<[string]> { + /** + * Allows to create new proxy contact and execute a message call to the new proxy within one transaction. + * @param args - Array[masterCopy, data] + * @returns Array[proxyAddress] + */ + createProxy: SafeProxyFactoryContract_v1_1_1_Function<'createProxy'> = async (args) => { 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()] - } + /** + * Allows to create new proxy contract, execute a message call to the new proxy and call a specified callback within one transaction. + * @param args - Array[masterCopy, initializer, saltNonce, callback] + * @returns Array[proxyAddress] + */ + createProxyWithCallback: SafeProxyFactoryContract_v1_1_1_Function<'createProxyWithCallback'> = + async (args) => { + return [await this.contract.methods.createProxyWithCallback(...args).call()] + } - async createProxyWithNonce( - args: readonly [masterCopy: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param args - Array[masterCopy, initializer, saltNonce] + * @returns Array[proxyAddress] + */ + createProxyWithNonce: SafeProxyFactoryContract_v1_1_1_Function<'createProxyWithNonce'> = async ( + args + ) => { return [await this.contract.methods.createProxyWithNonce(...args).call()] } + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param {CreateProxyProps} props - Properties for the new proxy contract. + * @returns The address of the new proxy contract. + */ async createProxyWithOptions({ safeSingletonAddress, initializer, 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 index 05f1e9ea2..1fdcad58b 100644 --- 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 @@ -1,27 +1,20 @@ import { TransactionReceipt } from 'web3-core/types' -import SafeProxyFactoryBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3' +import SafeProxyFactoryBaseContractWeb3, { + CreateProxyProps +} 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 { DeepWriteable } 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 + SafeProxyFactoryContract_v1_3_0_Abi as SafeProxyFactoryContract_v1_3_0_Abi_Readonly, + SafeProxyFactoryContract_v1_3_0_Function } 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' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' -export interface CreateProxyProps extends CreateProxyPropsGeneral { - options?: Web3TransactionOptions -} +// Remove all nested `readonly` modifiers from the ABI type +type SafeProxyFactoryContract_v1_3_0_Abi = + DeepWriteable /** * SafeProxyFactoryContract_v1_3_0_Web3 is the implementation specific to the Safe Proxy Factory contract version 1.3.0. @@ -32,7 +25,7 @@ export interface CreateProxyProps extends CreateProxyPropsGeneral { * @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> + extends SafeProxyFactoryBaseContractWeb3 implements SafeProxyFactoryContract_v1_3_0_Contract { safeVersion: SafeVersion @@ -53,7 +46,7 @@ class SafeProxyFactoryContract_v1_3_0_Web3 ) { const safeVersion = '1.3.0' const defaultAbi = - safeProxyFactory_1_3_0_ContractArtifacts.abi as DeepWriteable + safeProxyFactory_1_3_0_ContractArtifacts.abi as SafeProxyFactoryContract_v1_3_0_Abi super( chainId, @@ -61,60 +54,73 @@ class SafeProxyFactoryContract_v1_3_0_Web3 defaultAbi, safeVersion, customContractAddress, - customContractAbi as DeepWriteable + customContractAbi as SafeProxyFactoryContract_v1_3_0_Abi ) 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]> { + /** + * Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address. + * @returns Array[creationCode] + */ + proxyCreationCode: SafeProxyFactoryContract_v1_3_0_Function<'proxyCreationCode'> = async () => { return [await this.contract.methods.proxyCreationCode().call()] } - async proxyRuntimeCode(): Promise<[string]> { + /** + * Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed. + * @returns Array[runtimeCode] + */ + proxyRuntimeCode: SafeProxyFactoryContract_v1_3_0_Function<'proxyRuntimeCode'> = async () => { 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()] - } + /** + * Allows to get the address for a new proxy contact created via `createProxyWithNonce`. + * @param args - Array[singleton, initializer, saltNonce] + * @returns Array[proxyAddress] + */ + calculateCreateProxyWithNonceAddress: SafeProxyFactoryContract_v1_3_0_Function<'calculateCreateProxyWithNonceAddress'> = + async (args) => { + return [await this.contract.methods.calculateCreateProxyWithNonceAddress(...args).call()] + } - async createProxy(args: readonly [singleton: string, data: string]): Promise<[string]> { + /** + * Allows to create new proxy contact and execute a message call to the new proxy within one transaction. + * @param args - Array[singleton, data] + * @returns Array[proxyAddress] + */ + createProxy: SafeProxyFactoryContract_v1_3_0_Function<'createProxy'> = async (args) => { 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()] - } + /** + * Allows to create new proxy contract, execute a message call to the new proxy and call a specified callback within one transaction. + * @param args - Array[singleton, initializer, saltNonce, callback] + * @returns Array[proxyAddress] + */ + createProxyWithCallback: SafeProxyFactoryContract_v1_3_0_Function<'createProxyWithCallback'> = + async (args) => { + return [await this.contract.methods.createProxyWithCallback(...args).call()] + } - async createProxyWithNonce( - args: readonly [singleton: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param args - Array[singleton, initializer, saltNonce] + * @returns Array[proxyAddress] + */ + createProxyWithNonce: SafeProxyFactoryContract_v1_3_0_Function<'createProxyWithNonce'> = async ( + args + ) => { return [await this.contract.methods.createProxyWithNonce(...args).call()] } + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param {CreateProxyProps} props - Properties for the new proxy contract. + * @returns The address of the new proxy contract. + */ async createProxyWithOptions({ safeSingletonAddress, initializer, 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 index d1f49a830..5ac1653e9 100644 --- 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 @@ -1,27 +1,20 @@ import { TransactionReceipt } from 'web3-core/types' -import SafeProxyFactoryBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/SafeProxyFactoryBaseContractWeb3' +import SafeProxyFactoryBaseContractWeb3, { + CreateProxyProps +} 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 { DeepWriteable } 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 + SafeProxyFactoryContract_v1_4_1_Abi as SafeProxyFactoryContract_v1_4_1_Abi_Readonly, + SafeProxyFactoryContract_v1_4_1_Function } 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' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' -export interface CreateProxyProps extends CreateProxyPropsGeneral { - options?: Web3TransactionOptions -} +// Remove all nested `readonly` modifiers from the ABI type +type SafeProxyFactoryContract_v1_4_1_Abi = + DeepWriteable /** * SafeProxyFactoryContract_v1_4_1_Web3 is the implementation specific to the Safe Proxy Factory contract version 1.4.1. @@ -32,7 +25,7 @@ export interface CreateProxyProps extends CreateProxyPropsGeneral { * @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> + extends SafeProxyFactoryBaseContractWeb3 implements SafeProxyFactoryContract_v1_4_1_Contract { safeVersion: SafeVersion @@ -53,7 +46,7 @@ class SafeProxyFactoryContract_v1_4_1_Web3 ) { const safeVersion = '1.4.1' const defaultAbi = - safeProxyFactory_1_4_1_ContractArtifacts.abi as DeepWriteable + safeProxyFactory_1_4_1_ContractArtifacts.abi as SafeProxyFactoryContract_v1_4_1_Abi super( chainId, @@ -61,66 +54,65 @@ class SafeProxyFactoryContract_v1_4_1_Web3 defaultAbi, safeVersion, customContractAddress, - customContractAbi as DeepWriteable + customContractAbi as SafeProxyFactoryContract_v1_4_1_Abi ) 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]> { + /** + * Returns the ID of the chain the contract is currently deployed on. + * @returns Array[chainId] + */ + getChainId: SafeProxyFactoryContract_v1_4_1_Function<'getChainId'> = async () => { return [await this.contract.methods.getChainId().call()] } - async proxyCreationCode(): Promise<[string]> { + /** + * Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address. + * @returns Array[creationCode] + */ + proxyCreationCode: SafeProxyFactoryContract_v1_4_1_Function<'proxyCreationCode'> = async () => { 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()] - } + /** + * Deploys a new chain-specific proxy with singleton and salt. Optionally executes an initializer call to a new proxy. + * @param args - Array[singleton, initializer, saltNonce] + * @returns Array[proxy] + */ + createChainSpecificProxyWithNonce: SafeProxyFactoryContract_v1_4_1_Function<'createChainSpecificProxyWithNonce'> = + async (args) => { + return [await this.contract.methods.createChainSpecificProxyWithNonce(...args).call()] + } - async createProxyWithCallback( - args: readonly [singleton: string, initializer: string, saltNonce: bigint, callback: string] - ): Promise<[string]> { - return [await this.contract.methods.createProxyWithCallback(...args).call()] - } + /** + * Deploy a new proxy with singleton and salt. + * Optionally executes an initializer call to a new proxy and calls a specified callback address. + * @param args - Array[singleton, initializer, saltNonce, callback] + * @returns Array[proxy] + */ + createProxyWithCallback: SafeProxyFactoryContract_v1_4_1_Function<'createProxyWithCallback'> = + async (args) => { + return [await this.contract.methods.createProxyWithCallback(...args).call()] + } - async createProxyWithNonce( - args: readonly [singleton: string, initializer: string, saltNonce: bigint] - ): Promise<[string]> { + /** + * Deploys a new proxy with singleton and salt. Optionally executes an initializer call to a new proxy. + * @param args - Array[singleton, initializer, saltNonce] + * @returns Array[proxy] + */ + createProxyWithNonce: SafeProxyFactoryContract_v1_4_1_Function<'createProxyWithNonce'> = async ( + args + ) => { return [await this.contract.methods.createProxyWithNonce(...args).call()] } + /** + * Allows to create new proxy contract and execute a message call to the new proxy within one transaction. + * @param {CreateProxyProps} props - Properties for the new proxy contract. + * @returns The address of the new proxy contract. + */ async createProxy({ safeSingletonAddress, initializer, @@ -136,9 +128,7 @@ class SafeProxyFactoryContract_v1_4_1_Web3 await this.estimateGas( 'createProxyWithNonce', [safeSingletonAddress, initializer, saltNonceBigInt], - { - ...options - } + { ...options } ) ).toString() } diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/SignMessageLibBaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/SignMessageLibBaseContractWeb3.ts index 4e90685b6..690b9c87d 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/SignMessageLibBaseContractWeb3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/SignMessageLibBaseContractWeb3.ts @@ -1,30 +1,28 @@ -import Contract from 'web3-eth-contract' +import { Abi } from 'abitype' import { AbiItem } from 'web3-utils' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import SignMessageLibBaseContract from '@safe-global/protocol-kit/adapters/SignMessageLibBaseContract' +import BaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/BaseContractWeb3' +import { contractName } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class SignMessageLibBaseContractWeb3 extends SignMessageLibBaseContract to specifically integrate with the Web3.js v6 library. + * Abstract class SignMessageLibBaseContractWeb3 extends BaseContractWeb3 to specifically integrate with the SignMessageLib contract. * It is designed to be instantiated for different versions of the SignMessageLib contract. * - * This abstract class sets up the Web3 v6 Contract object that interacts with a SignMessageLib contract version. - * * Subclasses of SignMessageLibBaseContractWeb3 are expected to represent specific versions of the SignMessageLib contract. * * @template SignMessageLibContractAbiType - The ABI type specific to the version of the SignMessageLib contract, extending InterfaceAbi from Web3. - * @extends SignMessageLibBaseContract - Extends the generic SignMessageLibBaseContract with Web3-specific implementation. + * @extends BaseContractWeb3 - Extends the generic BaseContractWeb3. * * Example subclasses: * - SignMessageLibContract_v1_4_1_Web3 extends SignMessageLibBaseContractWeb3 * - SignMessageLibContract_v1_3_0_Web3 extends SignMessageLibBaseContractWeb3 */ abstract class SignMessageLibBaseContractWeb3< - SignMessageLibContractAbiType extends AbiItem[] -> extends SignMessageLibBaseContract { - contract: Contract - adapter: Web3Adapter + SignMessageLibContractAbiType extends AbiItem[] & Abi +> extends BaseContractWeb3 { + contractName: contractName /** * @constructor @@ -45,10 +43,19 @@ abstract class SignMessageLibBaseContractWeb3< customContractAddress?: string, customContractAbi?: SignMessageLibContractAbiType ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'signMessageLibVersion' + + super( + contractName, + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi + ) - this.adapter = web3Adapter - this.contract = web3Adapter.getContract(this.contractAddress, this.contractAbi) + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Web3.ts index ae2781fac..16c094861 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Web3.ts @@ -6,16 +6,12 @@ import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' import SignMessageLibBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SignMessageLib/SignMessageLibBaseContractWeb3' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import SignMessageLibContract_v1_3_0_Contract, { - SignMessageLibContract_v1_3_0_Abi as SignMessageLibContract_v1_3_0_Abi_Readonly + SignMessageLibContract_v1_3_0_Abi as SignMessageLibContract_v1_3_0_Abi_Readonly, + SignMessageLibContract_v1_3_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/v1.3.0/SignMessageLibContract_v1_3_0' import signMessageLib_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SignMessageLib/v1.3.0/sign_message_lib' import { SafeVersion, SignMessageLibContract } from '@safe-global/safe-core-sdk-types' -import { - EncodeSignMessageLibFunction, - EstimateGasSignMessageLibFunction, - GetAddressSignMessageLibFunction, - SignMessageFunction -} from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/SignMessageLibBaseContract' +import { AdapterSpecificContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' // Remove all nested `readonly` modifiers from the ABI type type SignMessageLibContract_v1_3_0_Abi = DeepWriteable @@ -30,7 +26,7 @@ type SignMessageLibContract_v1_3_0_Abi = DeepWriteable - implements SignMessageLibContract_v1_3_0_Contract + implements SignMessageLibContract_v1_3_0_Contract { safeVersion: SafeVersion @@ -57,33 +53,20 @@ class SignMessageLibContract_v1_3_0_Web3 this.safeVersion = safeVersion } - encode: EncodeSignMessageLibFunction = ( - functionToEncode, - args - ) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - estimateGas: EstimateGasSignMessageLibFunction< - SignMessageLibContract_v1_3_0_Abi_Readonly, - Web3TransactionOptions - > = (functionToEstimate, args, options = {}) => { - return this.contract.methods[functionToEstimate](...args) - .estimateGas(options) - .then(BigInt) - } - - getAddress: GetAddressSignMessageLibFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - async getMessageHash(args: readonly [string]): Promise { + /** + * @param args - Array[message] + */ + getMessageHash: SignMessageLibContract_v1_3_0_Function<'getMessageHash'> = async (args) => { return [await this.contract.methods.getMessageHash(...args).call()] } - signMessage: SignMessageFunction< + /** + * @param args - Array[data] + */ + signMessage: AdapterSpecificContractFunction< SignMessageLibContract_v1_3_0_Abi_Readonly, - Web3TransactionOptions + Web3Adapter, + 'signMessage' > = async (data, options) => { if (options && !options.gas) { options.gas = Number(await this.estimateGas('signMessage', data, { ...options })) diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Web3.ts index bfd11a843..c059d7bda 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Web3.ts @@ -6,16 +6,12 @@ import { toTxResult } from '@safe-global/protocol-kit/adapters/web3/utils' import SignMessageLibBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SignMessageLib/SignMessageLibBaseContractWeb3' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import SignMessageLibContract_v1_4_1_Contract, { - SignMessageLibContract_v1_4_1_Abi as SignMessageLibContract_v1_4_1_Abi_Readonly + SignMessageLibContract_v1_4_1_Abi as SignMessageLibContract_v1_4_1_Abi_Readonly, + SignMessageLibContract_v1_4_1_Function } from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/v1.4.1/SignMessageLibContract_v1_4_1' import signMessageLib_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SignMessageLib/v1.4.1/sign_message_lib' import { SafeVersion, SignMessageLibContract } from '@safe-global/safe-core-sdk-types' -import { - EncodeSignMessageLibFunction, - EstimateGasSignMessageLibFunction, - GetAddressSignMessageLibFunction, - SignMessageFunction -} from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/SignMessageLibBaseContract' +import { AdapterSpecificContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' // Remove all nested `readonly` modifiers from the ABI type type SignMessageLibContract_v1_4_1_Abi = DeepWriteable @@ -30,7 +26,7 @@ type SignMessageLibContract_v1_4_1_Abi = DeepWriteable - implements SignMessageLibContract_v1_4_1_Contract + implements SignMessageLibContract_v1_4_1_Contract { safeVersion: SafeVersion @@ -57,33 +53,20 @@ class SignMessageLibContract_v1_4_1_Web3 this.safeVersion = safeVersion } - encode: EncodeSignMessageLibFunction = ( - functionToEncode, - args - ) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - estimateGas: EstimateGasSignMessageLibFunction< - SignMessageLibContract_v1_4_1_Abi_Readonly, - Web3TransactionOptions - > = (functionToEstimate, args, options = {}) => { - return this.contract.methods[functionToEstimate](...args) - .estimateGas(options) - .then(BigInt) - } - - getAddress: GetAddressSignMessageLibFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - async getMessageHash(args: readonly [string]): Promise { + /** + * @param args - Array[message] + */ + getMessageHash: SignMessageLibContract_v1_4_1_Function<'getMessageHash'> = async (args) => { return [await this.contract.methods.getMessageHash(...args).call()] } - signMessage: SignMessageFunction< + /** + * @param args - Array[data] + */ + signMessage: AdapterSpecificContractFunction< SignMessageLibContract_v1_4_1_Abi_Readonly, - Web3TransactionOptions + Web3Adapter, + 'signMessage' > = async (data, options) => { if (options && !options.gas) { options.gas = Number(await this.estimateGas('signMessage', data, { ...options })) diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractWeb3.ts index 31339cd9b..a1316c6e2 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractWeb3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractWeb3.ts @@ -1,30 +1,27 @@ -import Contract from 'web3-eth-contract' +import { Abi } from 'abitype' import { AbiItem } from 'web3-utils' - import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' -import SimulateTxAccessorBaseContract from '@safe-global/protocol-kit/adapters/SimulateTxAccessorBaseContract' import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import BaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/BaseContractWeb3' +import { contractName } from '@safe-global/protocol-kit/contracts/config' /** - * Abstract class SimulateTxAccessorBaseContractWeb3 extends SimulateTxAccessorBaseContract to specifically integrate with the Web3.js v6 library. + * Abstract class SimulateTxAccessorBaseContractWeb3 extends BaseContractWeb3 to specifically integrate with the SimulateTxAccessor contract. * It is designed to be instantiated for different versions of the Safe contract. * - * This abstract class sets up the Web3 v6 Contract object that interacts with a SimulateTxAccessor contract version. - * * Subclasses of SimulateTxAccessorBaseContractWeb3 are expected to represent specific versions of the contract. * * @template SimulateTxAccessorContractAbiType - The ABI type specific to the version of the SimulateTxAccessor contract, extending InterfaceAbi from Web3. - * @extends SimulateTxAccessorBaseContract - Extends the generic SimulateTxAccessorBaseContract with Web3-specific implementation. + * @extends BaseContractWeb3 - Extends the generic BaseContractWeb3. * * Example subclasses: * - SimulateTxAccessorContract_v1_4_1_Web3 extends SimulateTxAccessorBaseContractWeb3 * - SimulateTxAccessorContract_v1_3_0_Web3 extends SimulateTxAccessorBaseContractWeb3 */ abstract class SimulateTxAccessorBaseContractWeb3< - SimulateTxAccessorContractAbiType extends AbiItem[] -> extends SimulateTxAccessorBaseContract { - contract: Contract - adapter: Web3Adapter + SimulateTxAccessorContractAbiType extends AbiItem[] & Abi +> extends BaseContractWeb3 { + contractName: contractName /** * @constructor @@ -45,10 +42,19 @@ abstract class SimulateTxAccessorBaseContractWeb3< customContractAddress?: string, customContractAbi?: SimulateTxAccessorContractAbiType ) { - super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + const contractName = 'simulateTxAccessorVersion' + + super( + contractName, + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi + ) - this.adapter = web3Adapter - this.contract = web3Adapter.getContract(this.contractAddress, this.contractAbi) + this.contractName = contractName } } diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Web3.ts index f25f9b8a1..8e911372a 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Web3.ts @@ -1,16 +1,17 @@ import SimulateTxAccessorBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractWeb3' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import SimulateTxAccessorContract_v1_3_0_Contract, { - SimulateTxAccessorContract_v1_3_0_Abi + SimulateTxAccessorContract_v1_3_0_Abi as SimulateTxAccessorContract_v1_3_0_Abi_Readonly, + SimulateTxAccessorContract_v1_3_0_Function } from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0' import SimulateTxAccessor_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SimulateTxAccessor/v1.3.0/simulate_tx_accessor' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeSimulateTxAccessorFunction, - GetAddressSimulateTxAccessorFunction -} from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract' import { DeepWriteable } from '@safe-global/protocol-kit/adapters/web3/types' +// Remove all nested `readonly` modifiers from the ABI type +type SimulateTxAccessorContract_v1_3_0_Abi = + DeepWriteable + /** * SimulateTxAccessorContract_v1_3_0_Web3 is the implementation specific to the SimulateTxAccessor contract version 1.3.0. * @@ -20,7 +21,7 @@ import { DeepWriteable } from '@safe-global/protocol-kit/adapters/web3/types' * @implements SimulateTxAccessorContract_v1_3_0_Contract - Implements the interface specific to SimulateTxAccessor contract version 1.3.0. */ class SimulateTxAccessorContract_v1_3_0_Web3 - extends SimulateTxAccessorBaseContractWeb3> + extends SimulateTxAccessorBaseContractWeb3 implements SimulateTxAccessorContract_v1_3_0_Contract { safeVersion: SafeVersion @@ -41,7 +42,7 @@ class SimulateTxAccessorContract_v1_3_0_Web3 ) { const safeVersion = '1.3.0' const defaultAbi = - SimulateTxAccessor_1_3_0_ContractArtifacts.abi as DeepWriteable + SimulateTxAccessor_1_3_0_ContractArtifacts.abi as SimulateTxAccessorContract_v1_3_0_Abi super( chainId, @@ -49,26 +50,17 @@ class SimulateTxAccessorContract_v1_3_0_Web3 defaultAbi, safeVersion, customContractAddress, - customContractAbi as DeepWriteable + customContractAbi as SimulateTxAccessorContract_v1_3_0_Abi ) this.safeVersion = safeVersion } - getAddress: GetAddressSimulateTxAccessorFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - encode: EncodeSimulateTxAccessorFunction = ( - functionToEncode, - args - ) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - simulate: SimulateTxAccessorContract_v1_3_0_Contract['simulate'] = ( - args: readonly [to: string, value: bigint, data: string, operation: number] - ) => { + /** + * @param args - Array[to, value, data, operation] + * @returns Array[estimate, success, returnData] + */ + simulate: SimulateTxAccessorContract_v1_3_0_Function<'simulate'> = (args) => { return this.contract.methods.simulate(...args).call() } } diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Web3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Web3.ts index de8ffcb4d..da29b79a3 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Web3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Web3.ts @@ -1,16 +1,17 @@ import SimulateTxAccessorBaseContractWeb3 from '@safe-global/protocol-kit/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractWeb3' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import SimulateTxAccessorContract_v1_4_1_Contract, { - SimulateTxAccessorContract_v1_4_1_Abi + SimulateTxAccessorContract_v1_4_1_Abi as SimulateTxAccessorContract_v1_4_1_Abi_Readonly, + SimulateTxAccessorContract_v1_4_1_Function } from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1' import SimulateTxAccessor_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SimulateTxAccessor/v1.4.1/simulate_tx_accessor' import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EncodeSimulateTxAccessorFunction, - GetAddressSimulateTxAccessorFunction -} from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract' import { DeepWriteable } from '@safe-global/protocol-kit/adapters/web3/types' +// Remove all nested `readonly` modifiers from the ABI type +type SimulateTxAccessorContract_v1_4_1_Abi = + DeepWriteable + /** * SimulateTxAccessorContract_v1_4_1_Web3 is the implementation specific to the SimulateTxAccessor contract version 1.4.1. * @@ -20,7 +21,7 @@ import { DeepWriteable } from '@safe-global/protocol-kit/adapters/web3/types' * @implements SimulateTxAccessorContract_v1_4_1_Contract - Implements the interface specific to SimulateTxAccessor contract version 1.4.1. */ class SimulateTxAccessorContract_v1_4_1_Web3 - extends SimulateTxAccessorBaseContractWeb3> + extends SimulateTxAccessorBaseContractWeb3 implements SimulateTxAccessorContract_v1_4_1_Contract { safeVersion: SafeVersion @@ -41,7 +42,7 @@ class SimulateTxAccessorContract_v1_4_1_Web3 ) { const safeVersion = '1.4.1' const defaultAbi = - SimulateTxAccessor_1_4_1_ContractArtifacts.abi as DeepWriteable + SimulateTxAccessor_1_4_1_ContractArtifacts.abi as SimulateTxAccessorContract_v1_4_1_Abi super( chainId, @@ -49,26 +50,17 @@ class SimulateTxAccessorContract_v1_4_1_Web3 defaultAbi, safeVersion, customContractAddress, - customContractAbi as DeepWriteable + customContractAbi as SimulateTxAccessorContract_v1_4_1_Abi ) this.safeVersion = safeVersion } - getAddress: GetAddressSimulateTxAccessorFunction = () => { - return Promise.resolve(this.contract.options.address) - } - - encode: EncodeSimulateTxAccessorFunction = ( - functionToEncode, - args - ) => { - return this.contract.methods[functionToEncode](...args).encodeABI() - } - - simulate: SimulateTxAccessorContract_v1_4_1_Contract['simulate'] = ( - args: readonly [to: string, value: bigint, data: string, operation: number] - ) => { + /** + * @param args - Array[to, value, data, operation] + * @returns Array[estimate, success, returnData] + */ + simulate: SimulateTxAccessorContract_v1_4_1_Function<'simulate'> = (args) => { return this.contract.methods.simulate(...args).call() } } diff --git a/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts index dec034eb5..56ec5af9a 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts @@ -10,37 +10,36 @@ import SafeProxyFactoryContract_v1_3_0_Web3 from '@safe-global/protocol-kit/adap import SafeProxyFactoryContract_v1_4_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Web3' import SimulateTxAccessorContract_v1_3_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Web3' import SimulateTxAccessorContract_v1_4_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Web3' +import CreateCallContract_V1_3_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/CreateCall/v1.3.0/CreateCallContract_v1_3_0_Web3' +import CreateCallContract_V1_4_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/CreateCall/v1.4.1/CreateCallContract_v1_4_1_Web3' +import MultiSendContract_V1_1_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/MultiSend/v1.1.1/MultiSendContract_V1_1_1_Web3' +import MultiSendContract_V1_3_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/MultiSend/v1.3.0/MultiSendContract_V1_3_0_Web3' +import MultiSendContract_V1_4_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/MultiSend/v1.4.1/MultiSendContract_V1_4_1_Web3' +import MultiSendCallOnlyContract_V1_3_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/MultiSend/v1.3.0/MultiSendCallOnlyContract_V1_3_0_Web3' +import MultiSendCallOnlyContract_V1_4_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/MultiSend/v1.4.1/MultiSendCallOnlyContract_V1_4_1_Web3' +import SignMessageLibContract_v1_3_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SignMessageLib/v1.3.0/SignMessageLibContract_V1_3_0_Web3' +import SignMessageLibContract_v1_4_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SignMessageLib/v1.4.1/SignMessageLibContract_V1_4_1_Web3' +import CompatibilityFallbackHandlerContract_v1_4_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1_Web3' +import CompatibilityFallbackHandlerContract_v1_3_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0_Web3' import Web3Adapter from '@safe-global/protocol-kit/adapters/web3/Web3Adapter' import { SafeContract_v1_0_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/Safe/v1.0.0/SafeContract_v1_0_0' 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 { Compatibility_fallback_handler as CompatibilityFallbackHandler_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Compatibility_fallback_handler' -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 { SafeProxyFactoryContract_v1_0_0_Abi as SafeProxyFactoryContract_v1_0_0_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0' +import { SafeProxyFactoryContract_v1_1_1_Abi as SafeProxyFactoryContract_v1_1_1_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1' +import { SafeProxyFactoryContract_v1_3_0_Abi as SafeProxyFactoryContract_v1_3_0_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0' +import { SafeProxyFactoryContract_v1_4_1_Abi as SafeProxyFactoryContract_v1_4_1_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1' import { + CompatibilityFallbackHandlerContract, CreateCallContract, SafeVersion, SignMessageLibContract, SimulateTxAccessorContract } from '@safe-global/safe-core-sdk-types' -import CompatibilityFallbackHandler_V1_3_0_Web3 from './CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandler_V1_3_0_Web3' -import CompatibilityFallbackHandler_V1_4_1_Web3 from './CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandler_V1_4_1_Web3' -import CreateCallContract_V1_3_0_Web3 from './CreateCall/v1.3.0/CreateCallContract_v1_3_0_Web3' -import CreateCallContract_V1_4_1_Web3 from './CreateCall/v1.4.1/CreateCallContract_v1_4_1_Web3' -import MultiSendContract_V1_1_1_Web3 from './MultiSend/v1.1.1/MultiSendContract_V1_1_1_Web3' -import MultiSendContract_V1_3_0_Web3 from './MultiSend/v1.3.0/MultiSendContract_V1_3_0_Web3' -import MultiSendContract_V1_4_1_Web3 from './MultiSend/v1.4.1/MultiSendContract_V1_4_1_Web3' -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 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 { CreateCallContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/v1.4.1/CreateCallContract_v1_4_1' -import { CreateCallContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/v1.3.0/CreateCallContract_v1_3_0' +import { CreateCallContract_v1_4_1_Abi as CreateCallContract_v1_4_1_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/v1.4.1/CreateCallContract_v1_4_1' +import { CreateCallContract_v1_3_0_Abi as CreateCallContract_v1_3_0_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/v1.3.0/CreateCallContract_v1_3_0' import { MultiSendContract_v1_4_1_Abi as MultiSendContract_v1_4_1_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.4.1/MultiSendContract_v1_4_1' import { MultiSendContract_v1_3_0_Abi as MultiSendContract_v1_3_0_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.3.0/MultiSendContract_v1_3_0' import { MultiSendContract_v1_1_1_Abi as MultiSendContract_v1_1_1_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.1.1/MultiSendContract_v1_1_1' @@ -48,10 +47,14 @@ import { MultiSendCallOnlyContract_v1_3_0_Abi as MultiSendCallOnlyContract_v1_3_ import { MultiSendCallOnlyContract_v1_4_1_Abi as MultiSendCallOnlyContract_v1_4_1_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.4.1/MultiSendCallOnlyContract_v1_4_1' import { SignMessageLibContract_v1_4_1_Abi as SignMessageLibContract_v1_4_1_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/v1.4.1/SignMessageLibContract_v1_4_1' import { SignMessageLibContract_v1_3_0_Abi as SignMessageLibContract_v1_3_0_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/v1.3.0/SignMessageLibContract_v1_3_0' -import { SimulateTxAccessorContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0' -import { SimulateTxAccessorContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1' +import { SimulateTxAccessorContract_v1_3_0_Abi as SimulateTxAccessorContract_v1_3_0_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0' +import { SimulateTxAccessorContract_v1_4_1_Abi as SimulateTxAccessorContract_v1_4_1_Abi_Readonly } from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1' import { DeepWriteable } from '@safe-global/protocol-kit/adapters/web3/types' +import { CompatibilityFallbackHandlerContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1' +import { CompatibilityFallbackHandlerContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0' +type CreateCallContract_v1_3_0_Abi = DeepWriteable +type CreateCallContract_v1_4_1_Abi = DeepWriteable type MultiSendContract_v1_1_1_Abi = DeepWriteable type MultiSendContract_v1_3_0_Abi = DeepWriteable type MultiSendContract_v1_4_1_Abi = DeepWriteable @@ -61,6 +64,18 @@ type MultiSendCallOnlyContract_v1_4_1_Abi = DeepWriteable type SignMessageLibContract_v1_3_0_Abi = DeepWriteable type SignMessageLibContract_v1_4_1_Abi = DeepWriteable +type SimulateTxAccessorContract_v1_3_0_Abi = + DeepWriteable +type SimulateTxAccessorContract_v1_4_1_Abi = + DeepWriteable +type SafeProxyFactoryContract_v1_0_0_Abi = + DeepWriteable +type SafeProxyFactoryContract_v1_1_1_Abi = + DeepWriteable +type SafeProxyFactoryContract_v1_3_0_Abi = + DeepWriteable +type SafeProxyFactoryContract_v1_4_1_Abi = + DeepWriteable export async function getSafeContractInstance( safeVersion: SafeVersion, @@ -133,22 +148,29 @@ export async function getSafeContractInstance( } } -export function getCompatibilityFallbackHandlerContractInstance( +export async function getCompatibilityFallbackHandlerContractInstance( safeVersion: SafeVersion, - compatibilityFallbackhandlerContract: - | CompatibilityFallbackHandler_V1_4_1 - | CompatibilityFallbackHandler_V1_3_0 -): CompatibilityFallbackHandler_V1_4_1_Web3 | CompatibilityFallbackHandler_V1_3_0_Web3 { + contractAddress: string, + web3Adapter: Web3Adapter, + customContractAbi?: AbiItem | AbiItem[] | undefined +): Promise { + const chainId = await web3Adapter.getChainId() switch (safeVersion) { case '1.4.1': - return new CompatibilityFallbackHandler_V1_4_1_Web3( - compatibilityFallbackhandlerContract as CompatibilityFallbackHandler_V1_4_1 + return new CompatibilityFallbackHandlerContract_v1_4_1_Web3( + chainId, + web3Adapter, + contractAddress, + customContractAbi as unknown as CompatibilityFallbackHandlerContract_v1_4_1_Abi ) case '1.3.0': case '1.2.0': case '1.1.1': - return new CompatibilityFallbackHandler_V1_3_0_Web3( - compatibilityFallbackhandlerContract as CompatibilityFallbackHandler_V1_3_0 + return new CompatibilityFallbackHandlerContract_v1_3_0_Web3( + chainId, + web3Adapter, + contractAddress, + customContractAbi as unknown as CompatibilityFallbackHandlerContract_v1_3_0_Abi ) default: throw new Error('Invalid Safe version') diff --git a/packages/protocol-kit/src/contracts/AbiType/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContract.ts new file mode 100644 index 000000000..07f826f78 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContract.ts @@ -0,0 +1,13 @@ +import { Abi } from 'abitype' +import BaseContract from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' + +/** + * Represents the base contract type for a CompatibilityFallbackHandler contract. + * + * @template CompatibilityFallbackHandlerContractAbi - The ABI of the CompatibilityFallbackHandler contract. + * @type {CompatibilityFallbackHandlerBaseContract} + */ +type CompatibilityFallbackHandlerBaseContract = + BaseContract + +export default CompatibilityFallbackHandlerBaseContract diff --git a/packages/protocol-kit/src/contracts/AbiType/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0.ts b/packages/protocol-kit/src/contracts/AbiType/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0.ts new file mode 100644 index 000000000..ed643d73f --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/CompatibilityFallbackHandler/v1.3.0/CompatibilityFallbackHandlerContract_v1_3_0.ts @@ -0,0 +1,26 @@ +import { narrow } from 'abitype' +import compatibilityFallbackHandler_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.3.0/compatibility_fallback_handler' +import CompatibilityFallbackHandlerBaseContract from '@safe-global/protocol-kit/contracts/AbiType/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContract' + +const compatibilityFallbackHandlerContract_v1_3_0_AbiTypes = narrow( + compatibilityFallbackHandler_1_3_0_ContractArtifacts.abi +) + +/** + * Represents the ABI of the CompatibilityFallbackHandler contract version 1.3.0. + * + * @type {CompatibilityFallbackHandlerContract_v1_3_0_Abi} + */ +export type CompatibilityFallbackHandlerContract_v1_3_0_Abi = + typeof compatibilityFallbackHandlerContract_v1_3_0_AbiTypes + +/** + * Represents the contract type for a CompatibilityFallbackHandler contract version 1.3.0 defining read and write methods. + * Utilizes the generic CompatibilityFallbackHandlerBaseContract with the ABI specific to version 1.3.0. + * + * @type {CompatibilityFallbackHandlerContract_v1_3_0_Contract} + */ +type CompatibilityFallbackHandlerContract_v1_3_0_Contract = + CompatibilityFallbackHandlerBaseContract + +export default CompatibilityFallbackHandlerContract_v1_3_0_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1.ts b/packages/protocol-kit/src/contracts/AbiType/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1.ts new file mode 100644 index 000000000..bf32e8beb --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/CompatibilityFallbackHandler/v1.4.1/CompatibilityFallbackHandlerContract_v1_4_1.ts @@ -0,0 +1,26 @@ +import { narrow } from 'abitype' +import compatibilityFallbackHandler_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.4.1/compatibility_fallback_handler' +import CompatibilityFallbackHandlerBaseContract from '@safe-global/protocol-kit/contracts/AbiType/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContract' + +const compatibilityFallbackHandlerContract_v1_4_1_AbiTypes = narrow( + compatibilityFallbackHandler_1_4_1_ContractArtifacts.abi +) + +/** + * Represents the ABI of the CompatibilityFallbackHandler contract version 1.4.1. + * + * @type {CompatibilityFallbackHandlerContract_v1_4_1_Abi} + */ +export type CompatibilityFallbackHandlerContract_v1_4_1_Abi = + typeof compatibilityFallbackHandlerContract_v1_4_1_AbiTypes + +/** + * Represents the contract type for a CompatibilityFallbackHandler contract version 1.4.1 defining read and write methods. + * Utilizes the generic CompatibilityFallbackHandlerBaseContract with the ABI specific to version 1.4.1. + * + * @type {CompatibilityFallbackHandlerContract_v1_4_1_Contract} + */ +type CompatibilityFallbackHandlerContract_v1_4_1_Contract = + CompatibilityFallbackHandlerBaseContract + +export default CompatibilityFallbackHandlerContract_v1_4_1_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/CreateCall/CreateCallBaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/CreateCall/CreateCallBaseContract.ts index ec7ac24e0..c3f8c6cf5 100644 --- a/packages/protocol-kit/src/contracts/AbiType/CreateCall/CreateCallBaseContract.ts +++ b/packages/protocol-kit/src/contracts/AbiType/CreateCall/CreateCallBaseContract.ts @@ -1,128 +1,25 @@ -import { - Abi, - AbiParametersToPrimitiveTypes, - ExtractAbiFunction, - ExtractAbiFunctionNames -} from 'abitype' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import { - EthersTransactionOptions, - EthersTransactionResult -} from '@safe-global/protocol-kit/adapters/ethers' -import { - Web3TransactionOptions, - Web3TransactionResult -} from '@safe-global/protocol-kit/adapters/web3' +import { Abi } from 'abitype' +import BaseContract, { + AdapterSpecificContractFunction, + ContractReadFunctionNames, + EstimateGasFunction +} from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' +import { EthAdapter } from '@safe-global/safe-core-sdk-types' /** - * Encodes a function call for a CreateCall contract. + * Represents the base contract type for a CreateCall contract. * * @template CreateCallContractAbi - The ABI of the CreateCall contract. - * @template CreateCallFunction - The function to encode, derived from the ABI. + * @template Adapter - The EthAdapter type to use. + * @type {CreateCallBaseContract} */ -export type EncodeCreateCallFunction< - CreateCallContractAbi extends Abi, // Abi of the CreateCall Contract, - CreateCallFunction extends - ExtractAbiFunctionNames = ExtractAbiFunctionNames -> = ( - functionToEncode: CreateCallFunction, - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - > -) => string - -export type GetAddressCreateCallFunction = () => Promise - -/** - * Estimates the gas required for a function call on a CreateCall contract. - * - * @template CreateCallContractAbi - The ABI of the CreateCall contract. - * @template CreateCallFunction - The function for which gas is being estimated, derived from the ABI. - */ -export type EstimateGasCreateCallFunction< - CreateCallContractAbi extends Abi, // Abi of the CreateCall Contract, - TransactionOptions extends EthersTransactionOptions | Web3TransactionOptions, - CreateCallFunction extends - ExtractAbiFunctionNames = ExtractAbiFunctionNames -> = ( - functionToEncode: CreateCallFunction, - params: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - >, - options?: TransactionOptions -) => Promise - -/** - * Extracts the names of read-only functions (view or pure) from a given CreateCall contract ABI. - * - * @template CreateCallContractAbi - The ABI of the CreateCall contract. - * @type {CreateCallContractReadFunctions} - */ -export type CreateCallContractReadFunctions = - ExtractAbiFunctionNames - -/** - * Deploys a new contract using the create opcode. - * - * @template CreateCallContractAbi - The ABI of the CreateCall contract. - */ -export type PerformCreateFunction< - CreateCallContractAbi extends Abi, // Abi of the CreateCall Contract, - TransactionOptions extends EthersTransactionOptions | Web3TransactionOptions -> = ( - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'] - >, - options?: TransactionOptions -) => Promise - -/** - * Deploys a new contract using the create2 opcode. - * - * @template CreateCallContractAbi - The ABI of the CreateCall contract. - */ -export type PerformCreate2Function< - CreateCallContractAbi extends Abi, // Abi of the CreateCall Contract, - TransactionOptions extends EthersTransactionOptions | Web3TransactionOptions -> = ( - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'] - >, - options?: TransactionOptions -) => Promise - -type CreateCallBaseContract = { - [ProxyFactoryFunction in CreateCallContractReadFunctions]: ( - // parameters - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - > - // returned values as a Promise - ) => Promise< - AbiParametersToPrimitiveTypes< - ExtractAbiFunction['outputs'], - 'outputs' - > - > -} & { - safeVersion: SafeVersion - encode: EncodeCreateCallFunction - getAddress: GetAddressCreateCallFunction - estimateGas: EstimateGasCreateCallFunction< - CreateCallContractAbi, - EthersTransactionOptions | Web3TransactionOptions - > - performCreate: PerformCreateFunction< - CreateCallContractAbi, - EthersTransactionOptions | Web3TransactionOptions - > - performCreate2: PerformCreate2Function< - CreateCallContractAbi, - EthersTransactionOptions | Web3TransactionOptions - > +export type CreateCallBaseContract< + CreateCallContractAbi extends Abi, + Adapter extends EthAdapter +> = BaseContract> & { + estimateGas: EstimateGasFunction + performCreate: AdapterSpecificContractFunction + performCreate2: AdapterSpecificContractFunction } export default CreateCallBaseContract diff --git a/packages/protocol-kit/src/contracts/AbiType/CreateCall/v1.3.0/CreateCallContract_v1_3_0.ts b/packages/protocol-kit/src/contracts/AbiType/CreateCall/v1.3.0/CreateCallContract_v1_3_0.ts index 1d32289e1..fd5e1bb19 100644 --- a/packages/protocol-kit/src/contracts/AbiType/CreateCall/v1.3.0/CreateCallContract_v1_3_0.ts +++ b/packages/protocol-kit/src/contracts/AbiType/CreateCall/v1.3.0/CreateCallContract_v1_3_0.ts @@ -1,6 +1,7 @@ import { narrow } from 'abitype' import createCall_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CreateCall/v1.3.0/create_call' import CreateCallBaseContract from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/CreateCallBaseContract' +import { EthAdapter } from '@safe-global/safe-core-sdk-types' const createCallContract_v1_3_0_AbiTypes = narrow(createCall_1_3_0_ContractArtifacts.abi) @@ -15,8 +16,12 @@ export type CreateCallContract_v1_3_0_Abi = typeof createCallContract_v1_3_0_Abi * Represents the contract type for a CreateCall contract version 1.3.0 defining read and write methods. * Utilizes the generic CreateCallBaseContract with the ABI specific to version 1.3.0. * + * @template Adapter - The EthAdapter type to use. * @type {CreateCallContract_v1_3_0_Contract} */ -type CreateCallContract_v1_3_0_Contract = CreateCallBaseContract +type CreateCallContract_v1_3_0_Contract = CreateCallBaseContract< + CreateCallContract_v1_3_0_Abi, + Adapter +> export default CreateCallContract_v1_3_0_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/CreateCall/v1.4.1/CreateCallContract_v1_4_1.ts b/packages/protocol-kit/src/contracts/AbiType/CreateCall/v1.4.1/CreateCallContract_v1_4_1.ts index c48b1e384..0d55ebcda 100644 --- a/packages/protocol-kit/src/contracts/AbiType/CreateCall/v1.4.1/CreateCallContract_v1_4_1.ts +++ b/packages/protocol-kit/src/contracts/AbiType/CreateCall/v1.4.1/CreateCallContract_v1_4_1.ts @@ -1,6 +1,7 @@ import { narrow } from 'abitype' import createCall_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/CreateCall/v1.4.1/create_call' import CreateCallBaseContract from '@safe-global/protocol-kit/contracts/AbiType/CreateCall/CreateCallBaseContract' +import { EthAdapter } from '@safe-global/safe-core-sdk-types' const createCallContract_v1_4_1_AbiTypes = narrow(createCall_1_4_1_ContractArtifacts.abi) @@ -15,8 +16,12 @@ export type CreateCallContract_v1_4_1_Abi = typeof createCallContract_v1_4_1_Abi * Represents the contract type for a CreateCall contract version 1.4.1 defining read and write methods. * Utilizes the generic CreateCallBaseContract with the ABI specific to version 1.4.1. * + * @template Adapter - The EthAdapter type to use. * @type {CreateCallContract_v1_4_1_Contract} */ -type CreateCallContract_v1_4_1_Contract = CreateCallBaseContract +type CreateCallContract_v1_4_1_Contract = CreateCallBaseContract< + CreateCallContract_v1_4_1_Abi, + Adapter +> export default CreateCallContract_v1_4_1_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/MultiSend/MultiSendBaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/MultiSend/MultiSendBaseContract.ts index 06785ffd1..4605b5c58 100644 --- a/packages/protocol-kit/src/contracts/AbiType/MultiSend/MultiSendBaseContract.ts +++ b/packages/protocol-kit/src/contracts/AbiType/MultiSend/MultiSendBaseContract.ts @@ -1,35 +1,15 @@ -import { - Abi, - AbiParametersToPrimitiveTypes, - ExtractAbiFunction, - ExtractAbiFunctionNames -} from 'abitype' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import { Abi } from 'abitype' +import BaseContract from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' /** - * Encodes a function call for a MultiSend contract. + * Represents the base contract type for a MultiSend contract. * * @template MultiSendContractAbi - The ABI of the MultiSend contract. - * @template MultiSendFunction - The function to encode, derived from the ABI. + * @type {MultiSendBaseContract} */ -export type EncodeMultiSendFunction< - MultiSendContractAbi extends Abi, // Abi of the MultiSend Contract, - MultiSendFunction extends - ExtractAbiFunctionNames = ExtractAbiFunctionNames -> = ( - functionToEncode: MultiSendFunction, - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - > -) => string - -export type GetAddressMultiSendFunction = () => Promise - -type MultiSendBaseContract = { - safeVersion: SafeVersion - encode: EncodeMultiSendFunction - getAddress: GetAddressMultiSendFunction -} +type MultiSendBaseContract = BaseContract< + MultiSendContractAbi, + never +> export default MultiSendBaseContract diff --git a/packages/protocol-kit/src/contracts/AbiType/MultiSend/MultiSendCallOnlyBaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/MultiSend/MultiSendCallOnlyBaseContract.ts index 0a79a336b..c90460954 100644 --- a/packages/protocol-kit/src/contracts/AbiType/MultiSend/MultiSendCallOnlyBaseContract.ts +++ b/packages/protocol-kit/src/contracts/AbiType/MultiSend/MultiSendCallOnlyBaseContract.ts @@ -1,35 +1,15 @@ -import { - Abi, - AbiParametersToPrimitiveTypes, - ExtractAbiFunction, - ExtractAbiFunctionNames -} from 'abitype' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import { Abi } from 'abitype' +import BaseContract from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' /** - * Encodes a function call for a MultiSendCallOnly contract. + * Represents the base contract type for a MultiSendCallOnly contract. * * @template MultiSendCallOnlyContractAbi - The ABI of the MultiSendCallOnly contract. - * @template MultiSendCallOnlyFunction - The function to encode, derived from the ABI. + * @type {MultiSendCallOnlyBaseContract} */ -export type EncodeMultiSendCallOnlyFunction< - MultiSendCallOnlyContractAbi extends Abi, // Abi of the MultiSendCallOnly Contract, - MultiSendCallOnlyFunction extends - ExtractAbiFunctionNames = ExtractAbiFunctionNames -> = ( - functionToEncode: MultiSendCallOnlyFunction, - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - > -) => string - -export type GetAddressMultiSendCallOnlyFunction = () => Promise - -type MultiSendCallOnlyBaseContract = { - safeVersion: SafeVersion - encode: EncodeMultiSendCallOnlyFunction - getAddress: GetAddressMultiSendCallOnlyFunction -} +type MultiSendCallOnlyBaseContract = BaseContract< + MultiSendCallOnlyContractAbi, + never +> export default MultiSendCallOnlyBaseContract diff --git a/packages/protocol-kit/src/contracts/AbiType/Safe/SafeBaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/Safe/SafeBaseContract.ts index d451be4c3..650112756 100644 --- a/packages/protocol-kit/src/contracts/AbiType/Safe/SafeBaseContract.ts +++ b/packages/protocol-kit/src/contracts/AbiType/Safe/SafeBaseContract.ts @@ -1,88 +1,8 @@ -import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers' -import { Web3TransactionOptions } from '@safe-global/protocol-kit/adapters/web3' -import { - Abi, - AbiParametersToPrimitiveTypes, - ExtractAbiFunction, - ExtractAbiFunctionNames -} from 'abitype' -import { SafeVersion } from '@safe-global/safe-core-sdk-types/dist/src' - -// see docs: https://abitype.dev/config -declare module 'abitype' { - export interface Register { - // AddressType: `0x${string}` - // BytesType: { - // inputs: `0x${string}` | Uint8Array - // outputs: `0x${string}` - // } - AddressType: string - BytesType: { - inputs: string - outputs: string - } - } -} - -/** - * Extracts the names of read-only functions (view or pure) from a given Safe contract ABI. - * - * @template SafeContractAbi - The ABI of the Safe contract. - * @type {SafeContractReadFunctions} - */ -export type SafeContractReadFunctions = ExtractAbiFunctionNames< - SafeContractAbi, - 'view' | 'pure' -> - -/** - * Extracts the names of write functions (nonpayable or payable) from a given Safe contract ABI. - * - * @template SafeContractAbi - The ABI of the Safe contract. - * @type {SafeContractWriteFunctions} - */ -export type SafeContractWriteFunctions = ExtractAbiFunctionNames< - SafeContractAbi, - 'nonpayable' | 'payable' -> - -/** - * Encodes a function call for a Safe contract. - * - * @template SafeContractAbi - The ABI of the Safe contract. - * @template SafeFunction - The function to encode, derived from the ABI. - */ -export type EncodeSafeFunction< - SafeContractAbi extends Abi, // Abi of the Safe Contract, - SafeFunction extends - ExtractAbiFunctionNames = ExtractAbiFunctionNames -> = ( - functionToEncode: SafeFunction, - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - > -) => string - -/** - * Estimates the gas required for a function call on a Safe contract. - * - * @template SafeContractAbi - The ABI of the Safe contract. - * @template SafeFunction - The function for which gas is being estimated, derived from the ABI. - */ -export type EstimateGasSafeFunction< - SafeContractAbi extends Abi, // Abi of the Safe Contract, - TransactionOptions extends EthersTransactionOptions | Web3TransactionOptions, - SafeFunction extends - ExtractAbiFunctionNames = ExtractAbiFunctionNames -> = ( - functionToEncode: SafeFunction, - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - >, - options?: TransactionOptions -) => Promise +import { Abi } from 'abitype' +import BaseContract, { + ContractReadFunctionNames, + EstimateGasFunction +} from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' /** * Represents the base contract type for a Safe contract, defining read methods and utility functions like encode and estimateGas. @@ -90,28 +10,11 @@ export type EstimateGasSafeFunction< * @template SafeContractAbi - The ABI of the Safe contract. * @type {SafeBaseContract} */ -type SafeBaseContract = { - // only define Read methods - [SafeFunction in SafeContractReadFunctions]: ( - // parameters - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - > - // returned values as a Promise - ) => Promise< - AbiParametersToPrimitiveTypes< - ExtractAbiFunction['outputs'], - 'outputs' - > - > -} & { - safeVersion: SafeVersion - encode: EncodeSafeFunction - estimateGas: EstimateGasSafeFunction< - SafeContractAbi, - EthersTransactionOptions | Web3TransactionOptions - > +type SafeBaseContract = BaseContract< + SafeContractAbi, + ContractReadFunctionNames +> & { + estimateGas: EstimateGasFunction } export default SafeBaseContract diff --git a/packages/protocol-kit/src/contracts/AbiType/Safe/v1.0.0/SafeContract_v1_0_0.ts b/packages/protocol-kit/src/contracts/AbiType/Safe/v1.0.0/SafeContract_v1_0_0.ts index 2baad4463..f2592662f 100644 --- a/packages/protocol-kit/src/contracts/AbiType/Safe/v1.0.0/SafeContract_v1_0_0.ts +++ b/packages/protocol-kit/src/contracts/AbiType/Safe/v1.0.0/SafeContract_v1_0_0.ts @@ -1,9 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, narrow } from 'abitype' import safe_1_0_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.0.0/gnosis_safe' -import SafeBaseContract, { - SafeContractReadFunctions, - SafeContractWriteFunctions -} from '../SafeBaseContract' +import SafeBaseContract from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const safeContract_v1_0_0_AbiTypes = narrow(safe_1_0_0_ContractArtifacts.abi) @@ -15,18 +13,14 @@ const safeContract_v1_0_0_AbiTypes = narrow(safe_1_0_0_ContractArtifacts.abi) export type SafeContract_v1_0_0_Abi = typeof safeContract_v1_0_0_AbiTypes /** - * Extracts the names of read-only functions (view or pure) specific to the Safe contract version 1.0.0. + * Represents the function type derived by the given function name from the Safe contract version 1.0.0 ABI. * - * @type {Safe_v1_0_0_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SafeContract_v1_0_0_Function} */ -export type Safe_v1_0_0_Read_Functions = SafeContractReadFunctions - -/** - * Extracts the names of write functions (nonpayable or payable) specific to the Safe contract version 1.0.0. - * - * @type {Safe_v1_0_0_Write_Functions} - */ -export type Safe_v1_0_0_Write_Functions = SafeContractWriteFunctions +export type SafeContract_v1_0_0_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a Safe contract version 1.0.0, defining read and write methods. diff --git a/packages/protocol-kit/src/contracts/AbiType/Safe/v1.1.1/SafeContract_v1_1_1.ts b/packages/protocol-kit/src/contracts/AbiType/Safe/v1.1.1/SafeContract_v1_1_1.ts index fe9d10124..d97ce8872 100644 --- a/packages/protocol-kit/src/contracts/AbiType/Safe/v1.1.1/SafeContract_v1_1_1.ts +++ b/packages/protocol-kit/src/contracts/AbiType/Safe/v1.1.1/SafeContract_v1_1_1.ts @@ -1,9 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, narrow } from 'abitype' import safe_1_1_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.1.1/gnosis_safe' -import SafeBaseContract, { - SafeContractReadFunctions, - SafeContractWriteFunctions -} from '../SafeBaseContract' +import SafeBaseContract from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const safeContract_v1_1_1_AbiTypes = narrow(safe_1_1_1_ContractArtifacts.abi) @@ -15,18 +13,14 @@ const safeContract_v1_1_1_AbiTypes = narrow(safe_1_1_1_ContractArtifacts.abi) export type SafeContract_v1_1_1_Abi = typeof safeContract_v1_1_1_AbiTypes /** - * Extracts the names of read-only functions (view or pure) specific to the Safe contract version 1.1.1. + * Represents the function type derived by the given function name from the Safe contract version 1.1.1 ABI. * - * @type {Safe_v1_1_1_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SafeContract_v1_1_1_Function} */ -export type Safe_v1_1_1_Read_Functions = SafeContractReadFunctions - -/** - * Extracts the names of write functions (nonpayable or payable) specific to the Safe contract version 1.1.1. - * - * @type {Safe_v1_1_1_Write_Functions} - */ -export type Safe_v1_1_1_Write_Functions = SafeContractWriteFunctions +export type SafeContract_v1_1_1_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a Safe contract version 1.1.1, defining read and write methods. diff --git a/packages/protocol-kit/src/contracts/AbiType/Safe/v1.2.0/SafeContract_v1_2_0.ts b/packages/protocol-kit/src/contracts/AbiType/Safe/v1.2.0/SafeContract_v1_2_0.ts index eaa50e590..1065a73f6 100644 --- a/packages/protocol-kit/src/contracts/AbiType/Safe/v1.2.0/SafeContract_v1_2_0.ts +++ b/packages/protocol-kit/src/contracts/AbiType/Safe/v1.2.0/SafeContract_v1_2_0.ts @@ -1,9 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, narrow } from 'abitype' import safe_1_2_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.2.0/gnosis_safe' -import SafeBaseContract, { - SafeContractReadFunctions, - SafeContractWriteFunctions -} from '../SafeBaseContract' +import SafeBaseContract from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const safeContract_v1_2_0_AbiTypes = narrow(safe_1_2_0_ContractArtifacts.abi) @@ -15,18 +13,14 @@ const safeContract_v1_2_0_AbiTypes = narrow(safe_1_2_0_ContractArtifacts.abi) export type SafeContract_v1_2_0_Abi = typeof safeContract_v1_2_0_AbiTypes /** - * Extracts the names of read-only functions (view or pure) specific to the Safe contract version 1.2.0. + * Represents the function type derived by the given function name from the Safe contract version 1.2.0 ABI. * - * @type {Safe_v1_2_0_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SafeContract_v1_2_0_Function} */ -export type Safe_v1_2_0_Read_Functions = SafeContractReadFunctions - -/** - * Extracts the names of write functions (nonpayable or payable) specific to the Safe contract version 1.2.0. - * - * @type {Safe_v1_2_0_Write_Functions} - */ -export type Safe_v1_2_0_Write_Functions = SafeContractWriteFunctions +export type SafeContract_v1_2_0_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a Safe contract version 1.2.0, defining read and write methods. diff --git a/packages/protocol-kit/src/contracts/AbiType/Safe/v1.3.0/SafeContract_v1_3_0.ts b/packages/protocol-kit/src/contracts/AbiType/Safe/v1.3.0/SafeContract_v1_3_0.ts index d422d99b5..ca9fb722d 100644 --- a/packages/protocol-kit/src/contracts/AbiType/Safe/v1.3.0/SafeContract_v1_3_0.ts +++ b/packages/protocol-kit/src/contracts/AbiType/Safe/v1.3.0/SafeContract_v1_3_0.ts @@ -1,9 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, narrow } from 'abitype' import safe_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.3.0/gnosis_safe_l2' -import SafeBaseContract, { - SafeContractReadFunctions, - SafeContractWriteFunctions -} from '../SafeBaseContract' +import SafeBaseContract from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const safeContract_v1_3_0_AbiTypes = narrow(safe_1_3_0_ContractArtifacts.abi) @@ -15,18 +13,14 @@ const safeContract_v1_3_0_AbiTypes = narrow(safe_1_3_0_ContractArtifacts.abi) export type SafeContract_v1_3_0_Abi = typeof safeContract_v1_3_0_AbiTypes /** - * Extracts the names of read-only functions (view or pure) specific to the Safe contract version 1.3.0. + * Represents the function type derived by the given function name from the Safe contract version 1.3.0 ABI. * - * @type {Safe_v1_3_0_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SafeContract_v1_3_0_Function} */ -export type Safe_v1_3_0_Read_Functions = SafeContractReadFunctions - -/** - * Extracts the names of write functions (nonpayable or payable) specific to the Safe contract version 1.3.0. - * - * @type {Safe_v1_3_0_Write_Functions} - */ -export type Safe_v1_3_0_Write_Functions = SafeContractWriteFunctions +export type SafeContract_v1_3_0_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a Safe contract version 1.3.0, defining read and write methods. diff --git a/packages/protocol-kit/src/contracts/AbiType/Safe/v1.4.1/SafeContract_v1_4_1.ts b/packages/protocol-kit/src/contracts/AbiType/Safe/v1.4.1/SafeContract_v1_4_1.ts index ed6a990d8..4f55635f6 100644 --- a/packages/protocol-kit/src/contracts/AbiType/Safe/v1.4.1/SafeContract_v1_4_1.ts +++ b/packages/protocol-kit/src/contracts/AbiType/Safe/v1.4.1/SafeContract_v1_4_1.ts @@ -1,9 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, narrow } from 'abitype' import safe_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/Safe/v1.4.1/safe_l2' -import SafeBaseContract, { - SafeContractReadFunctions, - SafeContractWriteFunctions -} from '../SafeBaseContract' +import SafeBaseContract from '@safe-global/protocol-kit/contracts/AbiType/Safe/SafeBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const safeContract_v1_4_1_AbiTypes = narrow(safe_1_4_1_ContractArtifacts.abi) @@ -15,18 +13,14 @@ const safeContract_v1_4_1_AbiTypes = narrow(safe_1_4_1_ContractArtifacts.abi) export type SafeContract_v1_4_1_Abi = typeof safeContract_v1_4_1_AbiTypes /** - * Extracts the names of read-only functions (view or pure) specific to the Safe contract version 1.4.1. + * Represents the function type derived by the given function name from the Safe contract version 1.4.1 ABI. * - * @type {Safe_v1_4_1_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SafeContract_v1_4_1_Function} */ -export type Safe_v1_4_1_Read_Functions = SafeContractReadFunctions - -/** - * Extracts the names of write functions (nonpayable or payable) specific to the Safe contract version 1.4.1. - * - * @type {Safe_v1_4_1_Write_Functions} - */ -export type Safe_v1_4_1_Write_Functions = SafeContractWriteFunctions +export type SafeContract_v1_4_1_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a Safe contract version 1.4.1, defining read and write methods. diff --git a/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract.ts index 96eac92a7..1be560541 100644 --- a/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract.ts +++ b/packages/protocol-kit/src/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract.ts @@ -1,68 +1,7 @@ -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 +import { Abi } from 'abitype' +import BaseContract, { + EstimateGasFunction +} from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' /** * Represents the base contract type for a Safe Proxy Factory contract. @@ -70,29 +9,9 @@ export type EstimateGasSafeProxyFactoryFunction< * @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 type SafeProxyFactoryBaseContract = + BaseContract & { + estimateGas: EstimateGasFunction + } 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 index 1dcd348a2..e2773c663 100644 --- 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 @@ -1,9 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, 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' +import SafeProxyFactoryBaseContract from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const safeProxyFactoryContract_v1_0_0_AbiTypes = narrow( safeProxyFactory_1_0_0_ContractArtifacts.abi @@ -17,20 +15,14 @@ const safeProxyFactoryContract_v1_0_0_AbiTypes = narrow( 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. + * Represents the function type derived by the given function name from the SafeProxyFactory contract version 1.0.0 ABI. * - * @type {SafeProxyFactory_v1_0_0_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SafeProxyFactoryContract_v1_0_0_Function} */ -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 +export type SafeProxyFactoryContract_v1_0_0_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a Safe Proxy Factory contract version 1.0.0, defining read and write methods. 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 index 3c16c3ca5..ff256003a 100644 --- 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 @@ -1,9 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, 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' +import SafeProxyFactoryBaseContract from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const safeProxyFactoryContract_v1_1_1_AbiTypes = narrow( safeProxyFactory_1_1_1_ContractArtifacts.abi @@ -17,20 +15,14 @@ const safeProxyFactoryContract_v1_1_1_AbiTypes = narrow( 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. + * Represents the function type derived by the given function name from the SafeProxyFactory contract version 1.1.1 ABI. * - * @type {SafeProxyFactory_v1_1_1_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SafeProxyFactoryContract_v1_1_1_Function} */ -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 +export type SafeProxyFactoryContract_v1_1_1_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a Safe Proxy Factory contract version 1.1.1, defining read and write methods. 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 index 186f0d966..5e48e1d47 100644 --- 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 @@ -1,9 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, 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' +import SafeProxyFactoryBaseContract from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const safeProxyFactoryContract_v1_3_0_AbiTypes = narrow( safeProxyFactory_1_3_0_ContractArtifacts.abi @@ -17,20 +15,14 @@ const safeProxyFactoryContract_v1_3_0_AbiTypes = narrow( 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. + * Represents the function type derived by the given function name from the SafeProxyFactory contract version 1.3.0 ABI. * - * @type {SafeProxyFactory_v1_3_0_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SafeProxyFactoryContract_v1_3_0_Function} */ -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 +export type SafeProxyFactoryContract_v1_3_0_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a Safe Proxy Factory contract version 1.3.0, defining read and write methods. 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 index 82e8cd828..d34084d9e 100644 --- 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 @@ -1,9 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, 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' +import SafeProxyFactoryBaseContract from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/SafeProxyFactoryBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const safeProxyFactoryContract_v1_4_1_AbiTypes = narrow( safeProxyFactory_1_4_1_ContractArtifacts.abi @@ -17,20 +15,14 @@ const safeProxyFactoryContract_v1_4_1_AbiTypes = narrow( 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. + * Represents the function type derived by the given function name from the SafeProxyFactory contract version 1.4.1 ABI. * - * @type {SafeProxyFactory_v1_4_1_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SafeProxyFactoryContract_v1_4_1_Function} */ -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 +export type SafeProxyFactoryContract_v1_4_1_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a Safe Proxy Factory contract version 1.4.1, defining read and write methods. diff --git a/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/SignMessageLibBaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/SignMessageLibBaseContract.ts index 361196a59..da8ed3c6a 100644 --- a/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/SignMessageLibBaseContract.ts +++ b/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/SignMessageLibBaseContract.ts @@ -1,119 +1,27 @@ -import { - EthersTransactionOptions, - EthersTransactionResult -} from '@safe-global/protocol-kit/adapters/ethers' -import { - Web3TransactionOptions, - Web3TransactionResult -} from '@safe-global/protocol-kit/adapters/web3' -import { - Abi, - AbiParametersToPrimitiveTypes, - ExtractAbiFunction, - ExtractAbiFunctionNames -} from 'abitype' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import { Abi } from 'abitype' +import BaseContract, { + AdapterSpecificContractFunction, + ContractReadFunctionNames, + EstimateGasFunction +} from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' +import { EthAdapter } from '@safe-global/safe-core-sdk-types' /** - * Extracts the names of read-only functions (view or pure) from a given SignMessageLib contract ABI. + * Represents the base contract type for a SignMessageLib contract. * * @template SignMessageLibContractAbi - The ABI of the SignMessageLib contract. - * @type {SignMessageLibContractReadFunctions} + * @template Adapter - The EthAdapter type to use. + * @type {SignMessageLibBaseContract} */ -export type SignMessageLibContractReadFunctions = - ExtractAbiFunctionNames - -/** - * Extracts the names of write functions (nonpayable or payable) from a given SignMessageLib contract ABI. - * - * @template SignMessageLibContractAbi - The ABI of the SignMessageLib contract. - * @type {SignMessageLibContractWriteFunctions} - */ -export type SignMessageLibContractWriteFunctions = - ExtractAbiFunctionNames - -/** - * Encodes a function call for a SignMessageLib contract. - * - * @template SignMessageLibContractAbi - The ABI of the SignMessageLib contract. - * @template SignMessageLibFunction - The function to encode, derived from the ABI. - */ -export type EncodeSignMessageLibFunction< - SignMessageLibContractAbi extends Abi, // Abi of the SignMessageLib Contract, - SignMessageLibFunction extends - ExtractAbiFunctionNames = ExtractAbiFunctionNames -> = ( - functionToEncode: SignMessageLibFunction, - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - > -) => string - -/** - * Estimates the gas required for a function call on a SignMessageLib contract. - * - * @template SignMessageLibContractAbi - The ABI of the SignMessageLib contract. - * @template SignMessageLibFunction - The function for which gas is being estimated, derived from the ABI. - */ -export type EstimateGasSignMessageLibFunction< - SignMessageLibContractAbi extends Abi, // Abi of the SignMessageLib Contract, - TransactionOptions extends EthersTransactionOptions | Web3TransactionOptions, - SignMessageLibFunction extends - ExtractAbiFunctionNames = ExtractAbiFunctionNames -> = ( - functionToEncode: SignMessageLibFunction, - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - >, - options?: TransactionOptions -) => Promise - -/** - * Estimates the gas required for a function call on a SignMessageLib contract. - * - * @template SignMessageLibContractAbi - The ABI of the SignMessageLib contract. - */ -export type SignMessageFunction< - SignMessageLibContractAbi extends Abi, // Abi of the SignMessageLib Contract, - TransactionOptions extends EthersTransactionOptions | Web3TransactionOptions -> = ( - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'] - >, - options?: TransactionOptions -) => Promise - -export type GetAddressSignMessageLibFunction = () => Promise - -type SignMessageLibBaseContract = { - // Read functions - [SafeFunction in SignMessageLibContractReadFunctions]: ( - // parameters - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - > - // returned values as a Promise - ) => Promise< - AbiParametersToPrimitiveTypes< - ExtractAbiFunction['outputs'], - 'outputs' - > - > -} & { - safeVersion: SafeVersion - encode: EncodeSignMessageLibFunction - getAddress: GetAddressSignMessageLibFunction - estimateGas: EstimateGasSignMessageLibFunction< - SignMessageLibContractAbi, - EthersTransactionOptions | Web3TransactionOptions - > - signMessage: SignMessageFunction< - SignMessageLibContractAbi, - EthersTransactionOptions | Web3TransactionOptions - > +type SignMessageLibBaseContract< + SignMessageLibContractAbi extends Abi, + Adapter extends EthAdapter +> = BaseContract< + SignMessageLibContractAbi, + ContractReadFunctionNames +> & { + estimateGas: EstimateGasFunction + signMessage: AdapterSpecificContractFunction } export default SignMessageLibBaseContract diff --git a/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/v1.3.0/SignMessageLibContract_v1_3_0.ts b/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/v1.3.0/SignMessageLibContract_v1_3_0.ts index 52a39014b..7425b94b6 100644 --- a/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/v1.3.0/SignMessageLibContract_v1_3_0.ts +++ b/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/v1.3.0/SignMessageLibContract_v1_3_0.ts @@ -1,9 +1,8 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, narrow } from 'abitype' import signMessageLib_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SignMessageLib/v1.3.0/sign_message_lib' -import SignMessageLibBaseContract, { - SignMessageLibContractReadFunctions, - SignMessageLibContractWriteFunctions -} from '../SignMessageLibBaseContract' +import SignMessageLibBaseContract from '../SignMessageLibBaseContract' +import { EthAdapter } from '@safe-global/safe-core-sdk-types' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const signMessageLibContract_v1_3_0_AbiTypes = narrow(signMessageLib_1_3_0_ContractArtifacts.abi) @@ -15,28 +14,23 @@ const signMessageLibContract_v1_3_0_AbiTypes = narrow(signMessageLib_1_3_0_Contr export type SignMessageLibContract_v1_3_0_Abi = typeof signMessageLibContract_v1_3_0_AbiTypes /** - * Extracts the names of read-only functions (view or pure) specific to the SignMessageLib contract version 1.3.0. + * Represents the function type derived by the given function name from the SignMessageLib contract version 1.3.0 ABI. * - * @type {SignMessageLib_v1_3_0_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SignMessageLibContract_v1_3_0_Function} */ -export type SignMessageLib_v1_3_0_Read_Functions = - SignMessageLibContractReadFunctions - -/** - * Extracts the names of write functions (nonpayable or payable) specific to the SignMessageLib contract version 1.3.0. - * - * @type {SignMessageLib_v1_3_0_Write_Functions} - */ -export type SignMessageLib_v1_3_0_Write_Functions = - SignMessageLibContractWriteFunctions +export type SignMessageLibContract_v1_3_0_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a SignMessageLib contract version 1.3.0 defining read and write methods. * Utilizes the generic SignMessageLibBaseContract with the ABI specific to version 1.3.0. * + * @template Adapter - The EthAdapter type to use. * @type {SignMessageLibContract_v1_3_0_Contract} */ -type SignMessageLibContract_v1_3_0_Contract = - SignMessageLibBaseContract +type SignMessageLibContract_v1_3_0_Contract = + SignMessageLibBaseContract export default SignMessageLibContract_v1_3_0_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/v1.4.1/SignMessageLibContract_v1_4_1.ts b/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/v1.4.1/SignMessageLibContract_v1_4_1.ts index edfcbc6ab..fbbb2c360 100644 --- a/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/v1.4.1/SignMessageLibContract_v1_4_1.ts +++ b/packages/protocol-kit/src/contracts/AbiType/SignMessageLib/v1.4.1/SignMessageLibContract_v1_4_1.ts @@ -1,9 +1,8 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, narrow } from 'abitype' import signMessageLib_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SignMessageLib/v1.4.1/sign_message_lib' -import SignMessageLibBaseContract, { - SignMessageLibContractReadFunctions, - SignMessageLibContractWriteFunctions -} from '../SignMessageLibBaseContract' +import SignMessageLibBaseContract from '../SignMessageLibBaseContract' +import { EthAdapter } from '@safe-global/safe-core-sdk-types' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const signMessageLibContract_v1_4_1_AbiTypes = narrow(signMessageLib_1_4_1_ContractArtifacts.abi) @@ -15,28 +14,23 @@ const signMessageLibContract_v1_4_1_AbiTypes = narrow(signMessageLib_1_4_1_Contr export type SignMessageLibContract_v1_4_1_Abi = typeof signMessageLibContract_v1_4_1_AbiTypes /** - * Extracts the names of read-only functions (view or pure) specific to the SignMessageLib contract version 1.4.1. + * Represents the function type derived by the given function name from the SignMessageLib contract version 1.4.1 ABI. * - * @type {SignMessageLib_v1_4_1_Read_Functions} + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SignMessageLibContract_v1_4_1_Function} */ -export type SignMessageLib_v1_4_1_Read_Functions = - SignMessageLibContractReadFunctions - -/** - * Extracts the names of write functions (nonpayable or payable) specific to the SignMessageLib contract version 1.4.1. - * - * @type {SignMessageLib_v1_4_1_Write_Functions} - */ -export type SignMessageLib_v1_4_1_Write_Functions = - SignMessageLibContractWriteFunctions +export type SignMessageLibContract_v1_4_1_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction /** * Represents the contract type for a SignMessageLib contract version 1.4.1 defining read and write methods. * Utilizes the generic SignMessageLibBaseContract with the ABI specific to version 1.4.1. * + * @template Adapter - The EthAdapter type to use. * @type {SignMessageLibContract_v1_4_1_Contract} */ -type SignMessageLibContract_v1_4_1_Contract = - SignMessageLibBaseContract +type SignMessageLibContract_v1_4_1_Contract = + SignMessageLibBaseContract export default SignMessageLibContract_v1_4_1_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract.ts index f086959dd..5ffd11257 100644 --- a/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract.ts +++ b/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract.ts @@ -1,48 +1,5 @@ -import { - Abi, - AbiParametersToPrimitiveTypes, - ExtractAbiFunction, - ExtractAbiFunctionNames -} from 'abitype' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' - -/** - * Extracts the names of read-only functions (view or pure) from a given SimulateTxAccessor contract ABI. - * - * @template SimulateTxAccessorContractAbi - The ABI of the SimulateTxAccessor contract. - * @type {SimulateTxAccessorContractReadFunctions} - */ -export type SimulateTxAccessorContractReadFunctions = - ExtractAbiFunctionNames - -/** - * Extracts the names of write functions (nonpayable or payable) from a given SimulateTxAccessor contract ABI. - * - * @template SimulateTxAccessorContractAbi - The ABI of the SimulateTxAccessor contract. - * @type {SimulateTxAccessorContractWriteFunctions} - */ -export type SimulateTxAccessorContractWriteFunctions = - ExtractAbiFunctionNames - -/** - * Encodes a function call for a SimulateTxAccessor contract. - * - * @template SimulateTxAccessorContractAbi - The ABI of the SimulateTxAccessor contract. - * @template SimulateTxAccessorFunction - The function to encode, derived from the ABI. - */ -export type EncodeSimulateTxAccessorFunction< - SimulateTxAccessorContractAbi extends Abi, - SimulateTxAccessorFunction extends - ExtractAbiFunctionNames = ExtractAbiFunctionNames -> = ( - functionToEncode: SimulateTxAccessorFunction, - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - > -) => string - -export type GetAddressSimulateTxAccessorFunction = () => Promise +import { Abi } from 'abitype' +import BaseContract from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' /** * Represents the base contract type for a SimulateTxAccessor contract. @@ -50,26 +7,7 @@ export type GetAddressSimulateTxAccessorFunction = () => Promise * @template SimulateTxAccessorContractAbi - The ABI of the SimulateTxAccessor contract. * @type {SimulateTxAccessorBaseContract} */ -type SimulateTxAccessorBaseContract = { - [SimulateTxAccessorFunction in - | SimulateTxAccessorContractReadFunctions - | SimulateTxAccessorContractWriteFunctions]: ( - // parameters - args: AbiParametersToPrimitiveTypes< - ExtractAbiFunction['inputs'], - 'inputs' - > - // returned values as a Promise - ) => Promise< - AbiParametersToPrimitiveTypes< - ExtractAbiFunction['outputs'], - 'outputs' - > - > -} & { - safeVersion: SafeVersion - getAddress: GetAddressSimulateTxAccessorFunction - encode: EncodeSimulateTxAccessorFunction -} +type SimulateTxAccessorBaseContract = + BaseContract export default SimulateTxAccessorBaseContract diff --git a/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0.ts b/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0.ts index 853d5ed32..0e982a211 100644 --- a/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0.ts +++ b/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0.ts @@ -1,6 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, narrow } from 'abitype' import simulateTxAccessor_1_3_0_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SimulateTxAccessor/v1.3.0/simulate_tx_accessor' import SimulateTxAccessorBaseContract from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const simulateTxAccessorContract_v1_3_0_AbiTypes = narrow( simulateTxAccessor_1_3_0_ContractArtifacts.abi @@ -14,6 +15,16 @@ const simulateTxAccessorContract_v1_3_0_AbiTypes = narrow( export type SimulateTxAccessorContract_v1_3_0_Abi = typeof simulateTxAccessorContract_v1_3_0_AbiTypes +/** + * Represents the function type derived by the given function name from the SimulateTxAccessor contract version 1.3.0 ABI. + * + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SimulateTxAccessorContract_v1_3_0_Function} + */ +export type SimulateTxAccessorContract_v1_3_0_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction + /** * Represents the contract type for a SimulateTxAccessor contract version 1.3.0 defining read and write methods. * Utilizes the generic SimulateTxAccessorBaseContract with the ABI specific to version 1.3.0. diff --git a/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1.ts b/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1.ts index 322b4808b..5adf43b85 100644 --- a/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1.ts +++ b/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1.ts @@ -1,6 +1,7 @@ -import { narrow } from 'abitype' +import { ExtractAbiFunctionNames, narrow } from 'abitype' import simulateTxAccessor_1_4_1_ContractArtifacts from '@safe-global/protocol-kit/contracts/AbiType/assets/SimulateTxAccessor/v1.4.1/simulate_tx_accessor' import SimulateTxAccessorBaseContract from '@safe-global/protocol-kit/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract' +import { ContractFunction } from '@safe-global/protocol-kit/contracts/AbiType/common/BaseContract' const simulateTxAccessorContract_v1_4_1_AbiTypes = narrow( simulateTxAccessor_1_4_1_ContractArtifacts.abi @@ -14,6 +15,16 @@ const simulateTxAccessorContract_v1_4_1_AbiTypes = narrow( export type SimulateTxAccessorContract_v1_4_1_Abi = typeof simulateTxAccessorContract_v1_4_1_AbiTypes +/** + * Represents the function type derived by the given function name from the SimulateTxAccessor contract version 1.4.1 ABI. + * + * @template ContractFunctionName - The function name, derived from the ABI. + * @type {SimulateTxAccessorContract_v1_4_1_Function} + */ +export type SimulateTxAccessorContract_v1_4_1_Function< + ContractFunctionName extends ExtractAbiFunctionNames +> = ContractFunction + /** * Represents the contract type for a SimulateTxAccessor contract version 1.4.1 defining read and write methods. * Utilizes the generic SimulateTxAccessorBaseContract with the ABI specific to version 1.4.1. diff --git a/packages/protocol-kit/src/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.3.0/compatibility_fallback_handler.ts b/packages/protocol-kit/src/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.3.0/compatibility_fallback_handler.ts new file mode 100644 index 000000000..c2b8acbb4 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.3.0/compatibility_fallback_handler.ts @@ -0,0 +1,530 @@ +// Source: https://github.com/safe-global/safe-deployments/blob/main/src/assets/v1.3.0/compatibility_fallback_handler.json +export default { + defaultAddress: '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + released: true, + contractName: 'CompatibilityFallbackHandler', + version: '1.3.0', + networkAddresses: { + '1': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '3': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '4': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '5': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '10': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '11': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '12': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '18': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '25': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '28': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '30': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '31': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '39': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '40': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '41': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '42': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '43': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '44': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '46': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '50': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '51': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '56': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '57': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '61': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '63': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '69': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '71': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '81': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '82': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '83': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '97': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '100': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '106': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '108': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '109': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '111': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '122': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '123': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '137': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '148': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '155': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '169': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '195': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '204': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '246': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '250': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '252': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '255': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '280': '0x2f870a80647BbC554F3a0EBD093f11B4d2a7492A', + '288': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '291': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '300': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '321': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '322': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '324': '0x2f870a80647BbC554F3a0EBD093f11B4d2a7492A', + '336': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '338': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '420': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '424': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '570': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '588': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '592': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '595': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '599': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '686': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '787': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '919': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1001': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1008': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1030': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1088': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1101': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1111': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1112': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1115': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1116': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1230': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1231': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1284': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1285': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1287': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1294': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1442': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1559': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1663': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1729': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1807': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1890': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1891': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1984': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1998': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '2001': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '2002': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '2008': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '2019': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '2020': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '2021': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '2221': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '2222': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '2358': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '3737': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '3776': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '4002': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '4202': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '4337': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '4460': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '4689': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '4918': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '4919': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '5000': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '5001': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '5003': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '5700': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '6102': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '7000': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '7001': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '7332': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '7341': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '7700': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '8192': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '8194': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '8217': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '8453': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '9000': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '9001': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '9728': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '10000': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '10001': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '10081': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '10200': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '10242': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '10243': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '11235': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '11437': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '11891': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '12357': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '13337': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '13371': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '13473': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '17000': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '17172': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '18231': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '23294': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '23295': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '34443': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '42161': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '42170': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '42220': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '43113': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '43114': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '43288': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '44787': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '45000': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '47805': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '54211': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '56288': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '57000': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '58008': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '59140': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '59144': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '71401': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '71402': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '73799': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '80001': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '80085': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '81457': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '84531': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '84532': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '103454': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '167008': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '200101': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '200202': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '333999': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '421611': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '421613': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '421614': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '534351': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '534352': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '534353': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '622277': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '713715': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '7777777': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '11155111': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '11155420': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '168587773': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '222000222': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '245022926': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '245022934': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '333000333': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '999999999': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1313161554': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1313161555': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '1666600000': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '1666700000': '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804', + '11297108099': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4', + '11297108109': '0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4' + }, + abi: [ + { + inputs: [], + name: 'NAME', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'VERSION', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'message', + type: 'bytes' + } + ], + name: 'getMessageHash', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'contract GnosisSafe', + name: 'safe', + type: 'address' + }, + { + internalType: 'bytes', + name: 'message', + type: 'bytes' + } + ], + name: 'getMessageHashForSafe', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getModules', + outputs: [ + { + internalType: 'address[]', + name: '', + type: 'address[]' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'bytes32', + name: '_dataHash', + type: 'bytes32' + }, + { + internalType: 'bytes', + name: '_signature', + type: 'bytes' + } + ], + name: 'isValidSignature', + outputs: [ + { + internalType: 'bytes4', + name: '', + type: 'bytes4' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'bytes', + name: '_data', + type: 'bytes' + }, + { + internalType: 'bytes', + name: '_signature', + type: 'bytes' + } + ], + name: 'isValidSignature', + outputs: [ + { + internalType: 'bytes4', + name: '', + type: 'bytes4' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'uint256[]', + name: '', + type: 'uint256[]' + }, + { + internalType: 'uint256[]', + name: '', + type: 'uint256[]' + }, + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + name: 'onERC1155BatchReceived', + outputs: [ + { + internalType: 'bytes4', + name: '', + type: 'bytes4' + } + ], + stateMutability: 'pure', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'uint256', + name: '', + type: 'uint256' + }, + { + internalType: 'uint256', + name: '', + type: 'uint256' + }, + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + name: 'onERC1155Received', + outputs: [ + { + internalType: 'bytes4', + name: '', + type: 'bytes4' + } + ], + stateMutability: 'pure', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'uint256', + name: '', + type: 'uint256' + }, + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + name: 'onERC721Received', + outputs: [ + { + internalType: 'bytes4', + name: '', + type: 'bytes4' + } + ], + stateMutability: 'pure', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: 'targetContract', + type: 'address' + }, + { + internalType: 'bytes', + name: 'calldataPayload', + type: 'bytes' + } + ], + name: 'simulate', + outputs: [ + { + internalType: 'bytes', + name: 'response', + type: 'bytes' + } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { + internalType: 'bytes4', + name: 'interfaceId', + type: 'bytes4' + } + ], + name: 'supportsInterface', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'uint256', + name: '', + type: 'uint256' + }, + { + internalType: 'bytes', + name: '', + type: 'bytes' + }, + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + name: 'tokensReceived', + outputs: [], + stateMutability: 'pure', + type: 'function' + } + ] +} as const diff --git a/packages/protocol-kit/src/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.4.1/compatibility_fallback_handler.ts b/packages/protocol-kit/src/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.4.1/compatibility_fallback_handler.ts new file mode 100644 index 000000000..b59ebc1d8 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/assets/CompatibilityFallbackHandler/v1.4.1/compatibility_fallback_handler.ts @@ -0,0 +1,364 @@ +// Source: https://github.com/safe-global/safe-deployments/blob/main/src/assets/v1.4.1/compatibility_fallback_handler.json +export default { + defaultAddress: '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + released: true, + contractName: 'CompatibilityFallbackHandler', + version: '1.4.1', + networkAddresses: { + '1': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '5': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '10': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '56': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '71': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '97': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '100': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '137': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '1030': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '1101': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '1442': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '3636': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '4337': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '7771': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '8192': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '8194': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '8453': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '10242': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '10243': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '11235': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '13337': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '17000': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '42161': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '42220': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '54211': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '80001': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '81457': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '84531': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '84532': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '444444': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '11155111': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99', + '11155420': '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99' + }, + abi: [ + { + inputs: [ + { + internalType: 'contract Safe', + name: 'safe', + type: 'address' + }, + { + internalType: 'bytes', + name: 'message', + type: 'bytes' + } + ], + name: 'encodeMessageDataForSafe', + outputs: [ + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'bytes', + name: 'message', + type: 'bytes' + } + ], + name: 'getMessageHash', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'contract Safe', + name: 'safe', + type: 'address' + }, + { + internalType: 'bytes', + name: 'message', + type: 'bytes' + } + ], + name: 'getMessageHashForSafe', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [], + name: 'getModules', + outputs: [ + { + internalType: 'address[]', + name: '', + type: 'address[]' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'bytes32', + name: '_dataHash', + type: 'bytes32' + }, + { + internalType: 'bytes', + name: '_signature', + type: 'bytes' + } + ], + name: 'isValidSignature', + outputs: [ + { + internalType: 'bytes4', + name: '', + type: 'bytes4' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'bytes', + name: '_data', + type: 'bytes' + }, + { + internalType: 'bytes', + name: '_signature', + type: 'bytes' + } + ], + name: 'isValidSignature', + outputs: [ + { + internalType: 'bytes4', + name: '', + type: 'bytes4' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'uint256[]', + name: '', + type: 'uint256[]' + }, + { + internalType: 'uint256[]', + name: '', + type: 'uint256[]' + }, + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + name: 'onERC1155BatchReceived', + outputs: [ + { + internalType: 'bytes4', + name: '', + type: 'bytes4' + } + ], + stateMutability: 'pure', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'uint256', + name: '', + type: 'uint256' + }, + { + internalType: 'uint256', + name: '', + type: 'uint256' + }, + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + name: 'onERC1155Received', + outputs: [ + { + internalType: 'bytes4', + name: '', + type: 'bytes4' + } + ], + stateMutability: 'pure', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'uint256', + name: '', + type: 'uint256' + }, + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + name: 'onERC721Received', + outputs: [ + { + internalType: 'bytes4', + name: '', + type: 'bytes4' + } + ], + stateMutability: 'pure', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: 'targetContract', + type: 'address' + }, + { + internalType: 'bytes', + name: 'calldataPayload', + type: 'bytes' + } + ], + name: 'simulate', + outputs: [ + { + internalType: 'bytes', + name: 'response', + type: 'bytes' + } + ], + stateMutability: 'nonpayable', + type: 'function' + }, + { + inputs: [ + { + internalType: 'bytes4', + name: 'interfaceId', + type: 'bytes4' + } + ], + name: 'supportsInterface', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool' + } + ], + stateMutability: 'view', + type: 'function' + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'address', + name: '', + type: 'address' + }, + { + internalType: 'uint256', + name: '', + type: 'uint256' + }, + { + internalType: 'bytes', + name: '', + type: 'bytes' + }, + { + internalType: 'bytes', + name: '', + type: 'bytes' + } + ], + name: 'tokensReceived', + outputs: [], + stateMutability: 'pure', + type: 'function' + } + ] +} as const diff --git a/packages/protocol-kit/src/contracts/AbiType/common/BaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/common/BaseContract.ts new file mode 100644 index 000000000..f58b14835 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/common/BaseContract.ts @@ -0,0 +1,165 @@ +import { + Abi, + AbiParametersToPrimitiveTypes, + ExtractAbiFunction, + ExtractAbiFunctionNames +} from 'abitype' +import { + EthersAdapter, + EthersTransactionOptions, + EthersTransactionResult +} from '@safe-global/protocol-kit/adapters/ethers' +import { + Web3TransactionOptions, + Web3TransactionResult +} from '@safe-global/protocol-kit/adapters/web3' +import { EthAdapter, SafeVersion } from '@safe-global/safe-core-sdk-types' +import { DeepWriteable } from '@safe-global/protocol-kit/adapters/web3/types' + +/** + * Extracts the names of read-only functions (view or pure) from a given contract ABI. + * + * @template ContractAbi - The ABI of the contract. + * @type {ContractReadFunctionNames} + */ +export type ContractReadFunctionNames = ExtractAbiFunctionNames< + ContractAbi, + 'view' | 'pure' +> + +/** + * Extracts the names of write functions (nonpayable or payable) from a given contract ABI. + * + * @template ContractAbi - The ABI of the contract. + * @type {ContractWriteFunctionNames} + */ +export type ContractWriteFunctionNames = ExtractAbiFunctionNames< + ContractAbi, + 'nonpayable' | 'payable' +> + +/** + * Extracts the function arguments from a given contract ABI and function name. + * + * @template ContractAbi - The ABI of the contract. + * @template ContractFunctionName - The function name to extract arguments from, derived from the ABI. + * @template ArgType - The type of arguments to extract, either 'inputs' or 'outputs'. (default: 'inputs') + * @type {ExtractFunctionArgs} + */ +type ExtractFunctionArgs< + ContractAbi extends Abi, + ContractFunctionName extends + ExtractAbiFunctionNames = ExtractAbiFunctionNames, + ArgType extends 'inputs' | 'outputs' = 'inputs' +> = AbiParametersToPrimitiveTypes< + ExtractAbiFunction[ArgType], + ArgType +> + +/** + * Encodes a function call for a contract. + * + * @template ContractAbi - The ABI of the contract. + * @template ContractFunctionName - The function name to encode, derived from the ABI. + */ +export type EncodeFunction< + ContractAbi extends Abi, + ContractFunctionName extends + ExtractAbiFunctionNames = ExtractAbiFunctionNames +> = ( + functionToEncode: ContractFunctionName, + // TODO: remove `DeepWriteable` here when web3 dependency is removed + args: DeepWriteable> +) => string + +/** + * Estimates the gas required for a function call on a contract. + * + * @template ContractAbi - The ABI of the contract. + * @template TransactionOptions - The transaction options object. + * @template ContractFunctionName - The function for which gas is being estimated, derived from the ABI. + */ +export type EstimateGasFunction< + ContractAbi extends Abi, + TransactionOptions extends EthersTransactionOptions | Web3TransactionOptions = + | EthersTransactionOptions + | Web3TransactionOptions, + ContractFunctionName extends + ExtractAbiFunctionNames = ExtractAbiFunctionNames +> = ( + functionToEncode: ContractFunctionName, + // TODO: remove `DeepWriteable` here when web3 dependency is removed + args: DeepWriteable>, + options?: TransactionOptions +) => Promise + +export type GetAddressFunction = () => Promise + +/** + * Defines a function type for a contract, derived by the given function name from a given contract ABI. + * + * @template ContractAbi - The ABI of the contract. + * @template ContractFunctionName - The function name, derived from the ABI. + */ +export type ContractFunction< + ContractAbi extends Abi, + ContractFunctionName extends + ExtractAbiFunctionNames = ExtractAbiFunctionNames +> = ( + // input parameters (only if function has inputs, otherwise no parameters) + ...args: ExtractFunctionArgs['length'] extends 0 + ? [] + : // TODO: remove `DeepWriteable` here when web3 dependency is removed + [DeepWriteable>] + // returned values as a Promise +) => Promise> + +/** + * Defines an adapter-specific function type for a contract, derived by the given function name from a given contract ABI. + * + * @template ContractAbi - The ABI of the contract. + * @template Adapter - The EthAdapter type to use. + * @template ContractFunctionName - The function name, derived from the ABI. + * @template TransactionOptions - The transaction options type depending on the Adapter. + * @template TransactionResult - The transaction result type depending on the Adapter. + */ +export type AdapterSpecificContractFunction< + ContractAbi extends Abi, + Adapter extends EthAdapter, + ContractFunctionName extends + ExtractAbiFunctionNames = ExtractAbiFunctionNames, + TransactionOptions = Adapter extends EthersAdapter + ? EthersTransactionOptions + : Web3TransactionOptions, + TransactionResult = Adapter extends EthersAdapter + ? EthersTransactionResult + : Web3TransactionResult +> = ( + // TODO: remove `DeepWriteable` here when web3 dependency is removed + args: DeepWriteable< + AbiParametersToPrimitiveTypes['inputs']> + >, + options?: TransactionOptions +) => Promise + +/** + * Represents the base contract type for a contract. + * + * @template ContractAbi - The ABI of the contract. + * @template ContractFunctionNames - The function names, derived from the ABI. + * @type {BaseContract} + */ +type BaseContract< + ContractAbi extends Abi, + ContractFunctionNames extends ExtractAbiFunctionNames = + | ContractReadFunctionNames + | ContractWriteFunctionNames +> = { + [FunctionName in ContractFunctionNames]: ContractFunction +} & { + safeVersion: SafeVersion + encode: EncodeFunction + getAddress: GetAddressFunction +} + +export default BaseContract diff --git a/packages/protocol-kit/src/types/abi.d.ts b/packages/protocol-kit/src/types/abi.d.ts new file mode 100644 index 000000000..2dc388882 --- /dev/null +++ b/packages/protocol-kit/src/types/abi.d.ts @@ -0,0 +1,18 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { Abi } from 'abitype' + +// see docs: https://abitype.dev/config +declare module 'abitype' { + export interface Register { + // AddressType: `0x${string}` + // BytesType: { + // inputs: `0x${string}` | Uint8Array + // outputs: `0x${string}` + // } + AddressType: string + BytesType: { + inputs: string + outputs: string + } + } +}