import MinimumViableMultisig from "@counterfactual/cf-funding-protocol-contracts/expected-build-artifacts/MinimumViableMultisig.json" ; import { Node } from "@counterfactual/types" ; import { Interface , joinSignature , keccak256 , Signature , solidityPack } from "ethers/utils" ; import { sortSignaturesBySignerAddress } from "../utils" ; import { EthereumCommitment , MultisigTransaction } from "./types" ; export abstract class MultisigCommitment extends EthereumCommitment { constructor ( readonly multisigAddress , readonly multisigOwners ) { super ( ) ; } abstract getTransactionDetails ( ) ; public getSignedTransaction ( sigs ) { const multisigInput = this . getTransactionDetails ( ) ; const signaturesList = sortSignaturesBySignerAddress ( this . hashToSign ( ) , sigs ) . map ( joinSignature ) ; const txData = new Interface ( MinimumViableMultisig . abi ) . functions . execTransaction . encode ( [ multisigInput . to , multisigInput . value , multisigInput . data , multisigInput . operation , signaturesList ] ) ; return { to : this . multisigAddress , value : 0 , data : txData } ; } public hashToSign ( ) { const { to , value , data , operation } = this . getTransactionDetails ( ) ; return keccak256 ( solidityPack ( [ "bytes1" , "address[]" , "address" , "uint256" , "bytes" , "uint8" ] , [ "0x19" , this . multisigOwners , to , value , data , operation ] ) ) ; } }