import { BigNumber } from '@ethersproject/bignumber' ; import { ContractTransaction } from '@ethersproject/contracts' ; import { SafeTransaction , SafeTransactionData } from '@gnosis.pm/safe-core-sdk-types' ; import { GnosisSafe as GnosisSafe_V1_1_1 } from '../../../typechain/src/ethers-v5/v1.1.1/GnosisSafe' ; import { GnosisSafe as GnosisSafe_V1_2_0 } from '../../../typechain/src/ethers-v5/v1.2.0/GnosisSafe' ; import { GnosisSafe as GnosisSafe_V1_3_0 , GnosisSafeInterface } from '../../../typechain/src/ethers-v5/v1.3.0/GnosisSafe' ; import { EthersTransactionResult , TransactionOptions } from '../../utils/transactions/types' ; import GnosisSafeContract from './GnosisSafeContract' ; function toTxResult ( transactionResponse , options ? ) { return { hash : transactionResponse . hash , options , transactionResponse } ; } abstract class GnosisSafeContractEthers implements GnosisSafeContract { constructor ( public contract ) { } async getVersion ( ) { return this . contract . VERSION ( ) ; } getAddress ( ) { return this . contract . address ; } async getNonce ( ) { return ( await this . contract . nonce ( ) ) . toNumber ( ) ; } async getThreshold ( ) { return ( await this . contract . getThreshold ( ) ) . toNumber ( ) ; } async getOwners ( ) { return this . contract . getOwners ( ) ; } async isOwner ( address ) { return this . contract . isOwner ( address ) ; } async getTransactionHash ( safeTransactionData ) { return this . contract . getTransactionHash ( safeTransactionData . to , safeTransactionData . value , safeTransactionData . data , safeTransactionData . operation , safeTransactionData . safeTxGas , safeTransactionData . baseGas , safeTransactionData . gasPrice , safeTransactionData . gasToken , safeTransactionData . refundReceiver , safeTransactionData . nonce ) ; } async approvedHashes ( ownerAddress , hash ) { return this . contract . approvedHashes ( ownerAddress , hash ) ; } async approveHash ( hash , options ? ) { const txResponse = await this . contract . approveHash ( hash , options ) ; return toTxResult ( txResponse , options ) ; } abstract getModules ( ) ; abstract isModuleEnabled ( moduleAddress ) ; async execTransaction ( safeTransaction , options ? ) { const txResponse = await this . contract . execTransaction ( safeTransaction . data . to , safeTransaction . data . value , safeTransaction . data . data , safeTransaction . data . operation , safeTransaction . data . safeTxGas , safeTransaction . data . baseGas , safeTransaction . data . gasPrice , safeTransaction . data . gasToken , safeTransaction . data . refundReceiver , safeTransaction . encodedSignatures ( ) , options ) ; return toTxResult ( txResponse , options ) ; } encode : GnosisSafeInterface [ 'encodeFunctionData' ] = ( methodName , params ) : string => { return this . contract . interface . encodeFunctionData ( methodName , params ) ; } ; async estimateGas ( methodName , params , options ) { return ( await ( this . contract . estimateGas as any ) [ methodName ] ( ... params , options ) ) . toNumber ( ) ; } } export default GnosisSafeContractEthers ;