11import { expect } from "chai" ;
2- import { deployments , waffle } from "hardhat" ;
2+ import hre , { deployments , waffle } from "hardhat" ;
33import "@nomiclabs/hardhat-ethers" ;
44import { getDefaultCallbackHandler , getSafeWithOwners } from "../../test/utils/setup" ;
5- import { logGas , executeTx , SafeTransaction , safeSignTypedData , SafeSignature } from "../../test/utils/execution" ;
5+ import { logGas , executeTx , SafeTransaction , safeSignTypedData , SafeSignature , executeContractCallWithSigners } from "../../test/utils/execution" ;
66import { Wallet , Contract } from "ethers" ;
7+ import { AddressZero } from "@ethersproject/constants" ;
78
89const [ user1 , user2 , user3 , user4 , user5 ] = waffle . provider . getWallets ( ) ;
910
@@ -12,24 +13,29 @@ export interface Contracts {
1213 additions : any | undefined
1314}
1415
15- const generateTarget = async ( owners : Wallet [ ] , threshold : number ) => {
16+ const generateTarget = async ( owners : Wallet [ ] , threshold : number , guardAddress : string ) => {
1617 const fallbackHandler = await getDefaultCallbackHandler ( )
17- return await getSafeWithOwners ( owners . map ( ( owner ) => owner . address ) , threshold , fallbackHandler . address )
18+ const safe = await getSafeWithOwners ( owners . map ( ( owner ) => owner . address ) , threshold , fallbackHandler . address )
19+ await executeContractCallWithSigners ( safe , safe , "setGuard" , [ guardAddress ] , owners )
20+ return safe
1821}
1922
2023export const configs = [
2124 { name : "single owner" , signers : [ user1 ] , threshold : 1 } ,
22- { name : "2 out of 2" , signers : [ user1 , user2 ] , threshold : 2 } ,
25+ { name : "single owner and guard" , signers : [ user1 ] , threshold : 1 , useGuard : true } ,
26+ { name : "2 out of 23" , signers : [ user1 , user2 ] , threshold : 2 } ,
2327 { name : "3 out of 3" , signers : [ user1 , user2 , user3 ] , threshold : 3 } ,
2428 { name : "3 out of 5" , signers : [ user1 , user2 , user3 , user4 , user5 ] , threshold : 3 } ,
2529]
2630
2731const setupBenchmarkContracts = async ( benchmarkFixture ?: ( ) => Promise < any > ) => {
2832 return await deployments . createFixture ( async ( { deployments } ) => {
2933 await deployments . fixture ( ) ;
34+ const guardFactory = await hre . ethers . getContractFactory ( "DelegateCallTransactionGuard" ) ;
35+ const guard = await guardFactory . deploy ( AddressZero )
3036 const targets = [ ]
3137 for ( const config of configs ) {
32- targets . push ( await generateTarget ( config . signers , config . threshold ) )
38+ targets . push ( await generateTarget ( config . signers , config . threshold , config . useGuard ? guard . address : AddressZero ) )
3339 }
3440 return {
3541 targets,
@@ -40,7 +46,7 @@ const setupBenchmarkContracts = async (benchmarkFixture?: () => Promise<any>) =>
4046
4147export interface Benchmark {
4248 name : string ,
43- prepare : ( contracts : Contracts , target : string ) => Promise < SafeTransaction > ,
49+ prepare : ( contracts : Contracts , target : string , nonce : number ) => Promise < SafeTransaction > ,
4450 after ?: ( contracts : Contracts ) => Promise < void > ,
4551 fixture ?: ( ) => Promise < any >
4652}
@@ -52,7 +58,7 @@ export const benchmark = async (topic: string, benchmarks: Benchmark[]) => {
5258 describe ( `${ topic } - ${ name } ` , async ( ) => {
5359 it ( "with an EOA" , async ( ) => {
5460 const contracts = await contractSetup ( )
55- const tx = await prepare ( contracts , user2 . address )
61+ const tx = await prepare ( contracts , user2 . address , 0 )
5662 await logGas ( name , user2 . sendTransaction ( {
5763 to : tx . to ,
5864 value : tx . value ,
@@ -65,7 +71,8 @@ export const benchmark = async (topic: string, benchmarks: Benchmark[]) => {
6571 it ( `with a ${ config . name } Safe` , async ( ) => {
6672 const contracts = await contractSetup ( )
6773 const target = contracts . targets [ i ]
68- const tx = await prepare ( contracts , target . address )
74+ const nonce = await target . nonce ( ) ;
75+ const tx = await prepare ( contracts , target . address , nonce )
6976 const threshold = await target . getThreshold ( )
7077 const sigs : SafeSignature [ ] = await Promise . all ( config . signers . slice ( 0 , threshold ) . map ( async ( signer ) => {
7178 return await safeSignTypedData ( signer , target , tx )
0 commit comments