Last active
May 25, 2022 11:13
-
-
Save clemsos/84281a119bccc3387d5884c20a604dae to your computer and use it in GitHub Desktop.
Hardhat script to generate all 4-bytes signature hashes for all Unlock contracts (shows a markdown array in the console)
This file contains hidden or 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
const contracts = require('@unlock-protocol/contracts') | |
const { ethers } = require('hardhat') | |
const md = (sigs) => { | |
// show markdown array on screen | |
console.log('| Type | Name | SigHash |') | |
console.log('|---|---|---|') | |
sigs.forEach(([type, name, sighash]) => | |
console.log(`| ${type} | ${name} | ${sighash} |`) | |
) | |
} | |
const sigs = (abi) => { | |
const { functions, events } = abi | |
const sigFuncs = Object.keys(functions).map((d) => [ | |
'function', | |
d, | |
abi.getSighash(functions[d]), | |
]) | |
const sigEvents = Object.keys(events).map((d) => [ | |
'events', | |
d, | |
abi.getSighash(events[d]), | |
]) | |
return [...sigFuncs, ...sigEvents] | |
} | |
async function main() { | |
const contractNames = [ | |
['Unlock', 9], | |
['Unlock', 10], | |
['Unlock', 11], | |
['PublicLock', 8], | |
['PublicLock', 9], | |
['PublicLock', 10] | |
] | |
console.log('# Unlock contracts 4-bytes signatures \n') | |
for (let i = 0; i < contractNames.length; i++) { | |
const [contractName, version] = contractNames[i]; | |
const { abi: jsonAbi, bytecode } = contracts[`${contractName}V${version}`] | |
const { interface: abi } = await ethers.getContractFactory(jsonAbi, bytecode) | |
console.log( | |
`\n ## ${contractName} v${version} \n` | |
) | |
md(sigs(abi)) | |
} | |
} | |
// execute as standalone | |
if (require.main === module) { | |
/* eslint-disable promise/prefer-await-to-then, no-console */ | |
main() | |
.then(() => process.exit(0)) | |
.catch((error) => { | |
console.error(error) | |
process.exit(1) | |
}) | |
} | |
module.exports = main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment