-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: write Hardhat task for gas benchmark
- Loading branch information
Showing
4 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import fs from 'fs'; | ||
import { task } from 'hardhat/config'; | ||
import { Align, getMarkdownTable, Row } from 'markdown-table-ts'; | ||
|
||
task('gas-benchmark', 'Benchmark gas usage of the smart contracts based on predefined scenarios') | ||
.addParam( | ||
'compare', | ||
'The `.json` file that contains the gas costs of the currently compiled contracts (e.g: current working branch)', | ||
) | ||
.addParam( | ||
'against', | ||
'The `.json` file that contains the gas costs to compare against (e.g: the `develop` branch)', | ||
) | ||
.setAction(async function (args, hre, runSuper) { | ||
// TODO: WIP | ||
const currentBenchmark = JSON.parse(fs.readFileSync(args.compare, 'utf8')); | ||
const baseBenchmark = JSON.parse(fs.readFileSync(args.against, 'utf8')); | ||
|
||
const casesExecute: Row[] = []; | ||
|
||
for (const [key, value] of Object.entries(currentBenchmark['runtime_costs']['execute'])) { | ||
const gasDiffMainController = | ||
value['main_controller'] - | ||
baseBenchmark['runtime_costs']['execute'][key]['main_controller']; | ||
|
||
const gasDiffRestrictedController = | ||
value['restricted_controller'] - | ||
baseBenchmark['runtime_costs']['execute'][key]['restricted_controller']; | ||
|
||
casesExecute.push([ | ||
value['description'], | ||
value['main_controller'] + ` (${gasDiffMainController})`, | ||
value['restricted_controller'] + ` (${gasDiffRestrictedController})`, | ||
]); | ||
} | ||
|
||
const generatedTable = getMarkdownTable({ | ||
table: { | ||
head: ['`execute` scenarios', '👑 main controller', '🛃 restricted controller'], | ||
body: casesExecute, | ||
}, | ||
alignment: [Align.Left], | ||
}); | ||
|
||
const file = 'new_gas_benchmark.md'; | ||
|
||
fs.writeFileSync(file, generatedTable); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ | ||
"deployment_costs": { | ||
"Universal Profile": "", | ||
"Key Manager": "", | ||
"LSP1 Delegate UP": "", | ||
"LSP7 Digital Asset": "", | ||
"LSP8 Identifiable Digital Asset": "" | ||
}, | ||
"runtime_costs": { | ||
"execute": { | ||
"case_1": { | ||
"description": "LYX transfer --> to an EOA", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_2": { | ||
"description": "LYX transfer --> to a UP", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_3": { | ||
"description": "LSP7 token transfer --> to an EOA", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_4": { | ||
"description": "LSP7 token transfer --> to a UP", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_5": { | ||
"description": "LSP8 NFT transfer --> to an EOA", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_6": { | ||
"description": "LSP8 NFT transfer --> to a UP", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
} | ||
}, | ||
"setData": { | ||
"case_1": { | ||
"description": "Update Profile details (LSP3Profile Metadata)", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_2": { | ||
"description": "Add a new controller with permission to `SET_DATA` + 3x allowed data keys: <br/> `AddressPermissions[]` <br/> + `AddressPermissions[index]` <br/> + `AddressPermissions:Permissions:<controller>` <br/> + `AddressPermissions:AllowedERC725YDataKeys:<controller`)", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_3": { | ||
"description": "Update permissions of previous controller. Allow it now to `SUPER_SETDATA`", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_4": { | ||
"description": "Remove a controller: <br/> 1. decrease `AddressPermissions[]` Array length <br/> 2. remove the controller address at `AddressPermissions[index]` <br/> 3. set \"0x\" for the controller permissions under AddressPermissions:Permissions:<controller-address>", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_5": { | ||
"description": "Write 5x new LSP12 Issued Assets", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_6": { | ||
"description": "Update 3x data keys (first 3)", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_7": { | ||
"description": "Update 3x data keys (middle 3)", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_8": { | ||
"description": "Update 3x data keys (last 3)", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
}, | ||
"case_9": { | ||
"description": "Set 2 x new data keys + add 3x new controllers", | ||
"main_controller": "", | ||
"restricted_controller": "" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters