import { BigNumber } from '@ethersproject/bignumber' ; import { SafeTransaction , SafeTransactionData } from '@gnosis.pm/safe-core-sdk-types' ; import { PromiEvent , TransactionReceipt } from 'web3-core/types' ; import { GnosisSafe as GnosisSafe_V1_1_1 } from '../../../typechain/src/web3-v1/v1.1.1/gnosis_safe' ; import { GnosisSafe as GnosisSafe_V1_2_0 } from '../../../typechain/src/web3-v1/v1.2.0/gnosis_safe' ; import { GnosisSafe as GnosisSafe_V1_3_0 } from '../../../typechain/src/web3-v1/v1.3.0/gnosis_safe' ; import { TransactionOptions , Web3TransactionResult } from '../../utils/transactions/types' ; import GnosisSafeContract from './GnosisSafeContract' ; function toTxResult ( promiEvent , options ? ) { return new Promise ( ( resolve , reject ) => promiEvent . once ( 'transactionHash' , ( hash ) => resolve ( { hash , promiEvent , options } ) ) . catch ( reject ) ) ; } abstract class GnosisSafeContractWeb3 implements GnosisSafeContract { constructor ( public contract ) { } async getVersion ( ) { return this . contract . methods . VERSION ( ) . call ( ) ; } getAddress ( ) { return this . contract . options . address ; } async getNonce ( ) { return Number ( await this . contract . methods . nonce ( ) . call ( ) ) ; } async getThreshold ( ) { return Number ( await this . contract . methods . getThreshold ( ) . call ( ) ) ; } async getOwners ( ) { return this . contract . methods . getOwners ( ) . call ( ) ; } async isOwner ( address ) { return this . contract . methods . isOwner ( address ) . call ( ) ; } async getTransactionHash ( safeTransactionData ) { return this . contract . methods . getTransactionHash ( safeTransactionData . to , safeTransactionData . value , safeTransactionData . data , safeTransactionData . operation , safeTransactionData . safeTxGas , safeTransactionData . baseGas , safeTransactionData . gasPrice , safeTransactionData . gasToken , safeTransactionData . refundReceiver , safeTransactionData . nonce ) . call ( ) ; } async approvedHashes ( ownerAddress , hash ) { return BigNumber . from ( await this . contract . methods . approvedHashes ( ownerAddress , hash ) . call ( ) ) ; } async approveHash ( hash , options ? ) { const txResponse = this . contract . methods . approveHash ( hash ) . send ( options ) ; return toTxResult ( txResponse , options ) ; } abstract getModules ( ) ; abstract isModuleEnabled ( moduleAddress ) ; async execTransaction ( safeTransaction , options ? ) { const txResponse = this . contract . methods . 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 ( ) ) . send ( options ) ; return toTxResult ( txResponse , options ) ; } encode ( methodName , params ) { return ( this . contract . methods as any ) [ methodName ] ( ... params ) . encodeABI ( ) ; } async estimateGas ( methodName , params , options ) { return Number ( await ( this . contract . methods as any ) [ methodName ] ( ... params ) . estimateGas ( options ) ) ; } } export default GnosisSafeContractWeb3 ;