-
Notifications
You must be signed in to change notification settings - Fork 50
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
160 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) { | ||
Check warning on line 14 in scripts/ci/gas_benchmark.ts GitHub Actions / build
|
||
// 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,43 @@ | ||
{ | ||
"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": "" | ||
} | ||
} | ||
} | ||
} |
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