import { BigNumber } from "bignumber.js" ; import * as ABIDecoder from "abi-decoder" ; import * as Web3 from "web3" ; import { DharmaMultiSigWalletContract } from "../../../types/generated/dharma_multi_sig_wallet" ; import { BaseContract } from "../../../types/base_contract" ; import { Address , DecodedLog , MultiSigSubmissionEventArgs , TxData } from "../../../types/common" ; import { NULL_ADDRESS } from "./constants" ; import { Web3Utils } from "../../../utils/web3_utils" ; import { TIMELOCK_IN_SECONDS } from "../../../migrations/migration_constants" ; param multiSig param contract param methodName param args param txData return export async function submitMultiSigTransaction ( multiSig , contract , methodName , args , txData , web3Instance = web3 ) { ABIDecoder . addABI ( multiSig . abi ) ; const encodedTransaction = await contract . web3ContractInstance [ methodName ] . getData . apply ( null , args ) ; const txHash = await multiSig . submitTransaction . sendTransactionAsync ( contract . address , new BigNumber ( 0 ) , encodedTransaction , txData ) ; const receipt = await web3Instance . eth . getTransactionReceipt ( txHash ) ; const submission = ABIDecoder . decodeLogs ( receipt . logs ) [ 0 ] as DecodedLog < MultiSigSubmissionEventArgs > ; const transactionId = submission . events [ 0 ] . value ; ABIDecoder . removeABI ( multiSig . abi ) ; return transactionId ; } async function submitRequisiteMultiSigConfirmations ( multiSig , transactionId , accounts ) { for ( let i = 1 ; i < 3 ; i ++ ) { await multiSig . confirmTransaction . sendTransactionAsync ( new BigNumber ( transactionId ) , { from : accounts [ i ] , } ) ; } } async function submitAndConfirmMultiSigTransaction ( multiSig , contract , methodName , accounts , args = [ ] , txData ? , web3Instance = web3 ) { const transactionData = { from : accounts [ 0 ] , ... txData , } ; args . push ( transactionData ) ; const transactionId = await submitMultiSigTransaction ( multiSig , contract , methodName , args , transactionData , web3Instance ) ; await submitRequisiteMultiSigConfirmations ( multiSig , transactionId , accounts ) ; return transactionId ; } param { Web3 } web3 param { DharmaMultiSigWalletContract } multiSig param contract param { string } methodName param { Address [ ] } accounts param { any [ ] } args param { TxData } txData returns { Promise < string > } export async function multiSigExecuteAfterTimelock ( web3 , multiSig , contract , methodName , accounts , args = [ ] , timelock = TIMELOCK_IN_SECONDS , txData ? ) { const web3Utils = new Web3Utils ( web3 ) ; const transactionId = await submitAndConfirmMultiSigTransaction ( multiSig , contract , methodName , accounts , args , txData , web3 ) ; await web3Utils . increaseTime ( timelock ) ; const txHash = await multiSig . executeTransaction . sendTransactionAsync ( transactionId , txData ) ; const transaction = await multiSig . transactions . callAsync ( transactionId ) ; const [ destination , value , data , executedSuccessfully ] = transaction ; if ( ! executedSuccessfully ) { throw new Error ( `Multisig transaction with ID #${ transactionId } failed to execute.` ) ; } return txHash ; } param { Web3 } web3 param { DharmaMultiSigWalletContract } multiSig param contract param { string } methodName param { Address [ ] } accounts param { any [ ] } args param { TxData } txData returns { Promise < void > } export async function multiSigExecutePauseImmediately ( web3 , multiSig , contract , methodName , accounts , args = [ ] , txData ? ) { const web3Utils = new Web3Utils ( web3 ) ; const transactionId = await submitAndConfirmMultiSigTransaction ( multiSig , contract , methodName , accounts , args , txData , web3 ) ; const txHash = await multiSig . executePauseTransactionImmediately . sendTransactionAsync ( transactionId ) ; const transaction = await multiSig . transactions . callAsync ( transactionId ) ; const [ destination , value , data , executedSuccessfully ] = transaction ; if ( ! executedSuccessfully ) { throw new Error ( `Multisig transaction with ID #${ transactionId } failed to execute.` ) ; } return txHash ; }