diff --git a/packages/protocol-kit/scripts/generateTypechainFiles.ts b/packages/protocol-kit/scripts/generateTypechainFiles.ts index d6c767089..3913e3e00 100644 --- a/packages/protocol-kit/scripts/generateTypechainFiles.ts +++ b/packages/protocol-kit/scripts/generateTypechainFiles.ts @@ -16,12 +16,10 @@ const outDirTests = 'typechain/tests/' const safeContractsPath = '../../node_modules/@safe-global/safe-deployments/dist/assets' const safeContracts_V1_4_1 = [ - `${safeContractsPath}/v1.4.1/compatibility_fallback_handler.json`, - `${safeContractsPath}/v1.4.1/simulate_tx_accessor.json` + `${safeContractsPath}/v1.4.1/compatibility_fallback_handler.json` ].join(' ') const safeContracts_V1_3_0 = [ - `${safeContractsPath}/v1.3.0/compatibility_fallback_handler.json`, - `${safeContractsPath}/v1.3.0/simulate_tx_accessor.json` + `${safeContractsPath}/v1.3.0/compatibility_fallback_handler.json` ].join(' ') // Won't be included in dist/ folder diff --git a/packages/protocol-kit/src/adapters/SimulateTxAccessorBaseContract.ts b/packages/protocol-kit/src/adapters/SimulateTxAccessorBaseContract.ts new file mode 100644 index 000000000..023c2b659 --- /dev/null +++ b/packages/protocol-kit/src/adapters/SimulateTxAccessorBaseContract.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 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 41af95c0e..755150307 100644 --- a/packages/protocol-kit/src/adapters/ethers/EthersAdapter.ts +++ b/packages/protocol-kit/src/adapters/ethers/EthersAdapter.ts @@ -8,12 +8,12 @@ import { EthAdapterTransaction, GetContractProps, SafeEIP712Args, - SignMessageLibContract + SignMessageLibContract, + 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 SimulateTxAccessorEthersContract from './contracts/SimulateTxAccessor/SimulateTxAccessorEthersContract' import { getCompatibilityFallbackHandlerContractInstance, getCreateCallContractInstance, @@ -235,16 +235,21 @@ class EthersAdapter implements EthAdapter { async getSimulateTxAccessorContract({ 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 SimulateTxAccessor contract address') } - const signerOrProvider = this.#signer || this.#provider - return getSimulateTxAccessorContractInstance(safeVersion, contractAddress, signerOrProvider) + return getSimulateTxAccessorContractInstance( + safeVersion, + contractAddress, + this, + customContractAbi + ) } async getContractCode(address: string, blockTag?: string | number): Promise { diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractEthers.ts new file mode 100644 index 000000000..4257a8f19 --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractEthers.ts @@ -0,0 +1,59 @@ +import { Contract, ContractRunner, InterfaceAbi } from 'ethers' + +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' + +/** + * Abstract class SimulateTxAccessorBaseContractEthers extends SimulateTxAccessorBaseContract to specifically integrate with the Ethers.js v6 library. + * It is designed to be instantiated for different versions of the Safe contract. + * + * This abstract class sets up the Ethers v6 Contract object that interacts with a 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. + * + * 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 + + /** + * @constructor + * Constructs an instance of SimulateTxAccessorBaseContractEthers. + * + * @param chainId - The chain ID of the contract. + * @param ethersAdapter - An instance of EthersAdapter. + * @param defaultAbi - The default ABI for the SimulateTxAccessor 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: SimulateTxAccessorContractAbiType, + safeVersion: SafeVersion, + customContractAddress?: string, + customContractAbi?: SimulateTxAccessorContractAbiType, + runner?: ContractRunner | null + ) { + super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + + this.adapter = ethersAdapter + this.contract = new Contract( + this.contractAddress, + this.contractAbi, + runner || this.adapter.getSigner() + ) + } +} + +export default SimulateTxAccessorBaseContractEthers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorEthersContract.ts b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorEthersContract.ts deleted file mode 100644 index 0306dcb3f..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/SimulateTxAccessorEthersContract.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { - Simulate_tx_accessor as SimulateTxAccessor_V1_3_0, - Simulate_tx_accessorInterface as SimulateTxAccessorInterface -} from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/Simulate_tx_accessor' -import { Simulate_tx_accessor as SimulateTxAccessor_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/Simulate_tx_accessor' -import { SimulateTxAccessorContract } from '@safe-global/safe-core-sdk-types' - -abstract class SimulateTxAccessorEthersContract implements SimulateTxAccessorContract { - constructor(public contract: SimulateTxAccessor_V1_4_1 | SimulateTxAccessor_V1_3_0) {} - - getAddress(): Promise { - return this.contract.getAddress() - } - - encode: SimulateTxAccessorInterface['encodeFunctionData'] = ( - methodName: any, - params: any - ): string => { - return this.contract.interface.encodeFunctionData(methodName, params) - } -} - -export default SimulateTxAccessorEthersContract 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 deleted file mode 100644 index 1646cd048..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_V1_3_0_Ethers.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Simulate_tx_accessor as SimulateTxAccessor } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/Simulate_tx_accessor' -import SimulateTxAccessorEthersContract from '../SimulateTxAccessorEthersContract' - -class SimulateTxAccessorContract_V1_3_0_Ethers extends SimulateTxAccessorEthersContract { - constructor(public contract: SimulateTxAccessor) { - super(contract) - } -} - -export default SimulateTxAccessorContract_V1_3_0_Ethers 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 new file mode 100644 index 000000000..091e21f93 --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Ethers.ts @@ -0,0 +1,67 @@ +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 +} 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. + * + * This class specializes in handling interactions with the SimulateTxAccessor contract version 1.3.0 using Ethers.js v6. + * + * @extends SimulateTxAccessorBaseContractEthers - Inherits from SimulateTxAccessorBaseContractEthers with ABI specific to SimulateTxAccessor contract version 1.3.0. + * @implements SimulateTxAccessorContract_v1_3_0_Contract - Implements the interface specific to SimulateTxAccessor contract version 1.3.0. + */ +class SimulateTxAccessorContract_v1_3_0_Ethers + extends SimulateTxAccessorBaseContractEthers + implements SimulateTxAccessorContract_v1_3_0_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SimulateTxAccessorContract_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 SimulateTxAccessor 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?: SimulateTxAccessorContract_v1_3_0_Abi + ) { + const safeVersion = '1.3.0' + const defaultAbi = SimulateTxAccessor_1_3_0_ContractArtifacts.abi + + super(chainId, ethersAdapter, defaultAbi, safeVersion, customContractAddress, customContractAbi) + + 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] + ) => { + return this.contract.simulate(...args) + } +} + +export default SimulateTxAccessorContract_v1_3_0_Ethers 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 deleted file mode 100644 index 7315ed1ae..000000000 --- a/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_V1_4_1_Ethers.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Simulate_tx_accessor as SimulateTxAccessor } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/Simulate_tx_accessor' -import SimulateTxAccessorEthersContract from '../SimulateTxAccessorEthersContract' - -class SimulateTxAccessorContract_V1_4_1_Ethers extends SimulateTxAccessorEthersContract { - constructor(public contract: SimulateTxAccessor) { - super(contract) - } -} - -export default SimulateTxAccessorContract_V1_4_1_Ethers 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 new file mode 100644 index 000000000..19d42e26a --- /dev/null +++ b/packages/protocol-kit/src/adapters/ethers/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Ethers.ts @@ -0,0 +1,67 @@ +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 +} 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. + * + * This class specializes in handling interactions with the SimulateTxAccessor contract version 1.4.1 using Ethers.js v6. + * + * @extends SimulateTxAccessorBaseContractEthers - Inherits from SimulateTxAccessorBaseContractEthers with ABI specific to SimulateTxAccessor contract version 1.4.1. + * @implements SimulateTxAccessorContract_v1_4_1_Contract - Implements the interface specific to SimulateTxAccessor contract version 1.4.1. + */ +class SimulateTxAccessorContract_v1_4_1_Ethers + extends SimulateTxAccessorBaseContractEthers + implements SimulateTxAccessorContract_v1_4_1_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SimulateTxAccessorContract_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 SimulateTxAccessor 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?: SimulateTxAccessorContract_v1_4_1_Abi + ) { + const safeVersion = '1.4.1' + const defaultAbi = SimulateTxAccessor_1_4_1_ContractArtifacts.abi + + super(chainId, ethersAdapter, defaultAbi, safeVersion, customContractAddress, customContractAbi) + + 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] + ) => { + return this.contract.simulate(...args) + } +} + +export default SimulateTxAccessorContract_v1_4_1_Ethers diff --git a/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts b/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts index 2280320f4..a89049087 100644 --- a/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts +++ b/packages/protocol-kit/src/adapters/ethers/contracts/contractInstancesEthers.ts @@ -1,13 +1,12 @@ 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 { Simulate_tx_accessor__factory as SimulateTxAccessor_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.3.0/factories/Simulate_tx_accessor__factory' import { Compatibility_fallback_handler__factory as CompatibilityFallbackHandler_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/factories/Compatibility_fallback_handler__factory' -import { Simulate_tx_accessor__factory as SimulateTxAccessor_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v6/v1.4.1/factories/Simulate_tx_accessor__factory' import { CreateCallContract, SafeVersion, - SignMessageLibContract + 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' @@ -20,8 +19,6 @@ import MultiSendCallOnlyContract_V1_3_0_Ethers from './MultiSend/v1.3.0/MultiSen 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 SimulateTxAccessorContract_V1_3_0_Ethers from './SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_V1_3_0_Ethers' -import SimulateTxAccessorContract_V1_4_1_Ethers from './SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_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' @@ -31,25 +28,29 @@ import SafeProxyFactoryContract_v1_0_0_Ethers from '@safe-global/protocol-kit/ad import SafeProxyFactoryContract_v1_1_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1_Ethers' import SafeProxyFactoryContract_v1_3_0_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0_Ethers' import SafeProxyFactoryContract_v1_4_1_Ethers from '@safe-global/protocol-kit/adapters/ethers/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Ethers' +import 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 { 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 { 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' import { MultiSendContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.3.0/MultiSendContract_v1_3_0' import { MultiSendContract_v1_1_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.1.1/MultiSendContract_v1_1_1' import { MultiSendCallOnlyContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.3.0/MultiSendCallOnlyContract_v1_3_0' import { MultiSendCallOnlyContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/MultiSend/v1.4.1/MultiSendCallOnlyContract_v1_4_1' +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 { SignMessageLibContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/v1.4.1/SignMessageLibContract_v1_4_1' import { SignMessageLibContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SignMessageLib/v1.3.0/SignMessageLibContract_v1_3_0' import { SafeProxyFactoryContract_v1_0_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.0.0/SafeProxyFactoryContract_v1_0_0' import { SafeProxyFactoryContract_v1_1_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1' import { SafeProxyFactoryContract_v1_3_0_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0' import { SafeProxyFactoryContract_v1_4_1_Abi } from '@safe-global/protocol-kit/contracts/AbiType/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1' -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 { 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' export async function getSafeContractInstance( safeVersion: SafeVersion, @@ -347,25 +348,29 @@ export async function getCreateCallContractInstance( } } -export function getSimulateTxAccessorContractInstance( +export async function getSimulateTxAccessorContractInstance( safeVersion: SafeVersion, contractAddress: string, - signerOrProvider: AbstractSigner | Provider -): SimulateTxAccessorContract_V1_4_1_Ethers | SimulateTxAccessorContract_V1_3_0_Ethers { - let simulateTxAccessorContract + ethersAdapter: EthersAdapter, + customContractAbi?: AbiItem | AbiItem[] | undefined +): Promise { + const chainId = await ethersAdapter.getChainId() + switch (safeVersion) { case '1.4.1': - simulateTxAccessorContract = SimulateTxAccessor_V1_4_1.connect( + return new SimulateTxAccessorContract_V1_4_1_Ethers( + chainId, + ethersAdapter, contractAddress, - signerOrProvider + customContractAbi as unknown as SimulateTxAccessorContract_v1_4_1_Abi ) - return new SimulateTxAccessorContract_V1_4_1_Ethers(simulateTxAccessorContract) case '1.3.0': - simulateTxAccessorContract = SimulateTxAccessor_V1_3_0.connect( + return new SimulateTxAccessorContract_V1_3_0_Ethers( + chainId, + ethersAdapter, contractAddress, - signerOrProvider + customContractAbi as unknown as SimulateTxAccessorContract_v1_3_0_Abi ) - return new SimulateTxAccessorContract_V1_3_0_Ethers(simulateTxAccessorContract) 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 8bae0e3cd..fdb061187 100644 --- a/packages/protocol-kit/src/adapters/web3/Web3Adapter.ts +++ b/packages/protocol-kit/src/adapters/web3/Web3Adapter.ts @@ -1,13 +1,14 @@ import { generateTypedData, validateEip3770Address } from '@safe-global/protocol-kit/utils' import { SigningMethod } from '@safe-global/protocol-kit/types' import { + CreateCallContract, Eip3770Address, EthAdapter, EthAdapterTransaction, GetContractProps, SafeEIP712Args, SignMessageLibContract, - CreateCallContract + SimulateTxAccessorContract } from '@safe-global/safe-core-sdk-types' import Web3 from 'web3' import { Transaction } from 'web3-core' @@ -19,7 +20,6 @@ import { AbiItem } from 'web3-utils' import type { JsonRPCResponse, Provider } from 'web3/providers' import CompatibilityFallbackHandlerWeb3Contract from './contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerWeb3Contract' import SafeContractWeb3 from './contracts/Safe/SafeContractWeb3' -import SimulateTxAccessorWeb3Contract from './contracts/SimulateTxAccessor/SimulateTxAccessorWeb3Contract' import { getCompatibilityFallbackHandlerContractInstance, getCreateCallContractInstance, @@ -223,18 +223,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 SimulateTxAccessor contract address') } - const simulateTxAccessorContract = this.getContract( + return getSimulateTxAccessorContractInstance( + safeVersion, contractAddress, - customContractAbi ?? (singletonDeployment?.abi as AbiItem[]) + this, + customContractAbi ) - return getSimulateTxAccessorContractInstance(safeVersion, simulateTxAccessorContract) } getContract(address: string, abi: AbiItem | AbiItem[], options?: ContractOptions): any { diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractWeb3.ts new file mode 100644 index 000000000..31339cd9b --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorBaseContractWeb3.ts @@ -0,0 +1,55 @@ +import Contract from 'web3-eth-contract' +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' + +/** + * Abstract class SimulateTxAccessorBaseContractWeb3 extends SimulateTxAccessorBaseContract to specifically integrate with the Web3.js v6 library. + * 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. + * + * 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 + + /** + * @constructor + * Constructs an instance of SimulateTxAccessorBaseContractWeb3. + * + * @param chainId - The chain ID of the contract. + * @param web3Adapter - An instance of Web3Adapter. + * @param defaultAbi - The default ABI for the SimulateTxAccessor 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: SimulateTxAccessorContractAbiType, + safeVersion: SafeVersion, + customContractAddress?: string, + customContractAbi?: SimulateTxAccessorContractAbiType + ) { + super(chainId, defaultAbi, safeVersion, customContractAddress, customContractAbi) + + this.adapter = web3Adapter + this.contract = web3Adapter.getContract(this.contractAddress, this.contractAbi) + } +} + +export default SimulateTxAccessorBaseContractWeb3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorWeb3Contract.ts b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorWeb3Contract.ts deleted file mode 100644 index 03f4f6f14..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/SimulateTxAccessorWeb3Contract.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Simulate_tx_accessor as SimulateTxAccessor_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Simulate_tx_accessor' -import { Simulate_tx_accessor as SimulateTxAccessor_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Simulate_tx_accessor' -import { SimulateTxAccessorContract } from '@safe-global/safe-core-sdk-types' - -abstract class SimulateTxAccessorWeb3Contract implements SimulateTxAccessorContract { - constructor(public contract: SimulateTxAccessor_V1_4_1 | SimulateTxAccessor_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 SimulateTxAccessorWeb3Contract 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 deleted file mode 100644 index ae1b294b1..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_V1_3_0_Web3.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Simulate_tx_accessor as SimulateTxAccessor } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Simulate_tx_accessor' -import SimulateTxAccessorWeb3Contract from '../SimulateTxAccessorWeb3Contract' - -class SimulateTxAccessor_V1_3_0_Web3 extends SimulateTxAccessorWeb3Contract { - constructor(public contract: SimulateTxAccessor) { - super(contract) - } -} - -export default SimulateTxAccessor_V1_3_0_Web3 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 new file mode 100644 index 000000000..f25f9b8a1 --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0_Web3.ts @@ -0,0 +1,76 @@ +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 +} 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' + +/** + * SimulateTxAccessorContract_v1_3_0_Web3 is the implementation specific to the SimulateTxAccessor contract version 1.3.0. + * + * This class specializes in handling interactions with the SimulateTxAccessor contract version 1.3.0 using Web3.js. + * + * @extends SimulateTxAccessorBaseContractWeb3 - Inherits from SimulateTxAccessorBaseContractWeb3 with ABI specific to SimulateTxAccessor contract version 1.3.0. + * @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> + implements SimulateTxAccessorContract_v1_3_0_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SimulateTxAccessorContract_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 SimulateTxAccessor 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?: SimulateTxAccessorContract_v1_3_0_Abi + ) { + const safeVersion = '1.3.0' + const defaultAbi = + SimulateTxAccessor_1_3_0_ContractArtifacts.abi as DeepWriteable + + super( + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi as DeepWriteable + ) + + 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] + ) => { + return this.contract.methods.simulate(...args).call() + } +} + +export default SimulateTxAccessorContract_v1_3_0_Web3 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 deleted file mode 100644 index adfbf525a..000000000 --- a/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_V1_4_1_Web3.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Simulate_tx_accessor as SimulateTxAccessor } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Simulate_tx_accessor' -import SimulateTxAccessorWeb3Contract from '../SimulateTxAccessorWeb3Contract' - -class SimulateTxAccessor_V1_4_1_Web3 extends SimulateTxAccessorWeb3Contract { - constructor(public contract: SimulateTxAccessor) { - super(contract) - } -} - -export default SimulateTxAccessor_V1_4_1_Web3 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 new file mode 100644 index 000000000..de8ffcb4d --- /dev/null +++ b/packages/protocol-kit/src/adapters/web3/contracts/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1_Web3.ts @@ -0,0 +1,76 @@ +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 +} 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' + +/** + * SimulateTxAccessorContract_v1_4_1_Web3 is the implementation specific to the SimulateTxAccessor contract version 1.4.1. + * + * This class specializes in handling interactions with the SimulateTxAccessor contract version 1.4.1 using Web3.js. + * + * @extends SimulateTxAccessorBaseContractWeb3 - Inherits from SimulateTxAccessorBaseContractWeb3 with ABI specific to SimulateTxAccessor contract version 1.4.1. + * @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> + implements SimulateTxAccessorContract_v1_4_1_Contract +{ + safeVersion: SafeVersion + + /** + * Constructs an instance of SimulateTxAccessorContract_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 SimulateTxAccessor 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?: SimulateTxAccessorContract_v1_4_1_Abi + ) { + const safeVersion = '1.4.1' + const defaultAbi = + SimulateTxAccessor_1_4_1_ContractArtifacts.abi as DeepWriteable + + super( + chainId, + web3Adapter, + defaultAbi, + safeVersion, + customContractAddress, + customContractAbi as DeepWriteable + ) + + 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] + ) => { + return this.contract.methods.simulate(...args).call() + } +} + +export default SimulateTxAccessorContract_v1_4_1_Web3 diff --git a/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts b/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts index 187a5e36b..dec034eb5 100644 --- a/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts +++ b/packages/protocol-kit/src/adapters/web3/contracts/contractInstancesWeb3.ts @@ -8,6 +8,8 @@ import SafeProxyFactoryContract_v1_0_0_Web3 from '@safe-global/protocol-kit/adap import SafeProxyFactoryContract_v1_1_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/v1.1.1/SafeProxyFactoryContract_v1_1_1_Web3' import SafeProxyFactoryContract_v1_3_0_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/v1.3.0/SafeProxyFactoryContract_v1_3_0_Web3' import SafeProxyFactoryContract_v1_4_1_Web3 from '@safe-global/protocol-kit/adapters/web3/contracts/SafeProxyFactory/v1.4.1/SafeProxyFactoryContract_v1_4_1_Web3' +import 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 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' @@ -19,13 +21,12 @@ import { SafeProxyFactoryContract_v1_1_1_Abi } from '@safe-global/protocol-kit/c 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 { Simulate_tx_accessor as SimulateTxAccessor_V1_3_0 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.3.0/Simulate_tx_accessor' import { Compatibility_fallback_handler as CompatibilityFallbackHandler_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Compatibility_fallback_handler' -import { Simulate_tx_accessor as SimulateTxAccessor_V1_4_1 } from '@safe-global/protocol-kit/typechain/src/web3-v1/v1.4.1/Simulate_tx_accessor' import { CreateCallContract, SafeVersion, - SignMessageLibContract + 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' @@ -38,8 +39,8 @@ import MultiSendCallOnlyContract_V1_3_0_Web3 from './MultiSend/v1.3.0/MultiSendC 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 SimulateTxAccessorContract_V1_3_0_Web3 from './SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_V1_3_0_Web3' -import SimulateTxAccessorContract_V1_4_1_Web3 from './SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_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 { 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' @@ -47,9 +48,9 @@ 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 { 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 { DeepWriteable } from '../types' +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 { DeepWriteable } from '@safe-global/protocol-kit/adapters/web3/types' type MultiSendContract_v1_1_1_Abi = DeepWriteable type MultiSendContract_v1_3_0_Abi = DeepWriteable @@ -347,18 +348,28 @@ export async function getCreateCallContractInstance( } } -export function getSimulateTxAccessorContractInstance( +export async function getSimulateTxAccessorContractInstance( safeVersion: SafeVersion, - simulateTxAccessorContract: SimulateTxAccessor_V1_4_1 | SimulateTxAccessor_V1_3_0 -): SimulateTxAccessorContract_V1_4_1_Web3 | SimulateTxAccessorContract_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 SimulateTxAccessorContract_V1_4_1_Web3( - simulateTxAccessorContract as SimulateTxAccessor_V1_4_1 + return new SimulateTxAccessorContract_v1_4_1_Web3( + chainId, + web3Adapter, + contractAddress, + customContractAbi as unknown as SimulateTxAccessorContract_v1_4_1_Abi ) case '1.3.0': - return new SimulateTxAccessorContract_V1_3_0_Web3( - simulateTxAccessorContract as SimulateTxAccessor_V1_3_0 + return new SimulateTxAccessorContract_v1_3_0_Web3( + chainId, + web3Adapter, + contractAddress, + customContractAbi as unknown as SimulateTxAccessorContract_v1_3_0_Abi ) default: throw new Error('Invalid Safe version') diff --git a/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract.ts b/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract.ts new file mode 100644 index 000000000..f086959dd --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/SimulateTxAccessorBaseContract.ts @@ -0,0 +1,75 @@ +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 + +/** + * Represents the base contract type for a SimulateTxAccessor contract. + * + * @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 +} + +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 new file mode 100644 index 000000000..853d5ed32 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/v1.3.0/SimulateTxAccessorContract_v1_3_0.ts @@ -0,0 +1,26 @@ +import { 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' + +const simulateTxAccessorContract_v1_3_0_AbiTypes = narrow( + simulateTxAccessor_1_3_0_ContractArtifacts.abi +) + +/** + * Represents the ABI of the SimulateTxAccessor contract version 1.3.0. + * + * @type {SimulateTxAccessorContract_v1_3_0_Abi} + */ +export type SimulateTxAccessorContract_v1_3_0_Abi = + typeof simulateTxAccessorContract_v1_3_0_AbiTypes + +/** + * 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. + * + * @type {SimulateTxAccessorContract_v1_3_0_Contract} + */ +type SimulateTxAccessorContract_v1_3_0_Contract = + SimulateTxAccessorBaseContract + +export default SimulateTxAccessorContract_v1_3_0_Contract 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 new file mode 100644 index 000000000..322b4808b --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/SimulateTxAccessor/v1.4.1/SimulateTxAccessorContract_v1_4_1.ts @@ -0,0 +1,26 @@ +import { 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' + +const simulateTxAccessorContract_v1_4_1_AbiTypes = narrow( + simulateTxAccessor_1_4_1_ContractArtifacts.abi +) + +/** + * Represents the ABI of the SimulateTxAccessor contract version 1.4.1. + * + * @type {SimulateTxAccessorContract_v1_4_1_Abi} + */ +export type SimulateTxAccessorContract_v1_4_1_Abi = + typeof simulateTxAccessorContract_v1_4_1_AbiTypes + +/** + * 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. + * + * @type {SimulateTxAccessorContract_v1_4_1_Contract} + */ +type SimulateTxAccessorContract_v1_4_1_Contract = + SimulateTxAccessorBaseContract + +export default SimulateTxAccessorContract_v1_4_1_Contract diff --git a/packages/protocol-kit/src/contracts/AbiType/assets/SimulateTxAccessor/v1.3.0/simulate_tx_accessor.ts b/packages/protocol-kit/src/contracts/AbiType/assets/SimulateTxAccessor/v1.3.0/simulate_tx_accessor.ts new file mode 100644 index 000000000..f96cb3937 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/assets/SimulateTxAccessor/v1.3.0/simulate_tx_accessor.ts @@ -0,0 +1,252 @@ +// Source: https://github.com/safe-global/safe-deployments/blob/main/src/assets/v1.3.0/simulate_tx_accessor.json +export default { + defaultAddress: '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + released: true, + contractName: 'SimulateTxAccessor', + version: '1.3.0', + networkAddresses: { + '1': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '3': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '4': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '5': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '10': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '11': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '12': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '18': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '25': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '28': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '30': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '31': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '39': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '40': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '41': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '42': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '43': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '44': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '46': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '50': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '51': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '56': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '57': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '61': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '63': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '69': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '71': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '81': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '82': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '83': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '97': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '100': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '106': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '108': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '109': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '111': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '122': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '123': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '137': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '148': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '155': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '169': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '195': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '204': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '246': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '250': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '252': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '255': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '280': '0x4191E2e12E8BC5002424CE0c51f9947b02675a44', + '288': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '291': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '300': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '321': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '322': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '324': '0x4191E2e12E8BC5002424CE0c51f9947b02675a44', + '336': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '338': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '420': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '424': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '570': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '588': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '592': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '595': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '599': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '686': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '787': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '919': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1001': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1008': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1030': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1088': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1101': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1111': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1112': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1115': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1116': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1230': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1231': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1284': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1285': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1287': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1294': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1442': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1559': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1663': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1807': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1890': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1891': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1984': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1998': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '2001': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '2002': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '2008': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '2019': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '2020': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '2021': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '2221': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '2222': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '2358': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '3737': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '3776': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '4002': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '4202': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '4337': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '4460': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '4689': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '4918': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '4919': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '5000': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '5001': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '5003': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '5700': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '6102': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '7001': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '7332': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '7341': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '7700': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '8192': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '8194': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '8217': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '8453': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '9000': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '9001': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '9728': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '10000': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '10001': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '10081': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '10200': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '10242': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '10243': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '11235': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '11437': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '11891': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '12357': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '13337': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '17000': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '17172': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '18231': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '23294': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '23295': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '34443': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '42161': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '42170': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '42220': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '43113': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '43114': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '43288': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '44787': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '45000': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '47805': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '54211': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '56288': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '57000': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '58008': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '59140': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '59144': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '71401': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '71402': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '73799': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '80001': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '80085': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '81457': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '84531': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '84532': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '103454': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '167008': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '200101': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '200202': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '333999': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '421611': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '421613': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '421614': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '534351': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '534352': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '534353': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '622277': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '713715': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '7777777': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '11155111': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '11155420': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '168587773': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '222000222': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '245022926': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '245022934': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '333000333': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '999999999': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1313161554': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1313161555': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '1666600000': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '1666700000': '0x727a77a074D1E6c4530e814F89E618a3298FC044', + '11297108099': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da', + '11297108109': '0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da' + }, + abi: [ + { + inputs: [], + stateMutability: 'nonpayable', + type: 'constructor' + }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address' + }, + { + internalType: 'uint256', + name: 'value', + type: 'uint256' + }, + { + internalType: 'bytes', + name: 'data', + type: 'bytes' + }, + { + internalType: 'enum Enum.Operation', + name: 'operation', + type: 'uint8' + } + ], + name: 'simulate', + outputs: [ + { + internalType: 'uint256', + name: 'estimate', + type: 'uint256' + }, + { + internalType: 'bool', + name: 'success', + type: 'bool' + }, + { + internalType: 'bytes', + name: 'returnData', + type: 'bytes' + } + ], + stateMutability: 'nonpayable', + type: 'function' + } + ] +} as const diff --git a/packages/protocol-kit/src/contracts/AbiType/assets/SimulateTxAccessor/v1.4.1/simulate_tx_accessor.ts b/packages/protocol-kit/src/contracts/AbiType/assets/SimulateTxAccessor/v1.4.1/simulate_tx_accessor.ts new file mode 100644 index 000000000..918646860 --- /dev/null +++ b/packages/protocol-kit/src/contracts/AbiType/assets/SimulateTxAccessor/v1.4.1/simulate_tx_accessor.ts @@ -0,0 +1,91 @@ +// Source: https://github.com/safe-global/safe-deployments/blob/main/src/assets/v1.4.1/simulate_tx_accessor.json +export default { + defaultAddress: '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + released: true, + contractName: 'SimulateTxAccessor', + version: '1.4.1', + networkAddresses: { + '1': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '5': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '10': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '56': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '71': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '97': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '100': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '137': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '1030': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '1101': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '1442': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '3636': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '4337': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '7771': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '8192': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '8194': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '8453': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '10242': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '10243': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '11235': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '13337': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '17000': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '42161': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '42220': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '54211': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '80001': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '81457': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '84531': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '84532': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '11155111': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199', + '11155420': '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199' + }, + abi: [ + { + inputs: [], + stateMutability: 'nonpayable', + type: 'constructor' + }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address' + }, + { + internalType: 'uint256', + name: 'value', + type: 'uint256' + }, + { + internalType: 'bytes', + name: 'data', + type: 'bytes' + }, + { + internalType: 'enum Enum.Operation', + name: 'operation', + type: 'uint8' + } + ], + name: 'simulate', + outputs: [ + { + internalType: 'uint256', + name: 'estimate', + type: 'uint256' + }, + { + internalType: 'bool', + name: 'success', + type: 'bool' + }, + { + internalType: 'bytes', + name: 'returnData', + type: 'bytes' + } + ], + stateMutability: 'nonpayable', + type: 'function' + } + ] +} as const diff --git a/packages/protocol-kit/src/utils/transactions/gas.ts b/packages/protocol-kit/src/utils/transactions/gas.ts index c69180834..cd515c588 100644 --- a/packages/protocol-kit/src/utils/transactions/gas.ts +++ b/packages/protocol-kit/src/utils/transactions/gas.ts @@ -81,6 +81,7 @@ export async function estimateGas( data, operation ]) + const safeFunctionToEstimate = safeContract.encode('simulateAndRevert', [ await simulateTxAccessorContract.getAddress(), transactionDataToEstimate