-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove Python requirement for contracts development. (#1144)
- Loading branch information
Showing
14 changed files
with
132 additions
and
220 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
This file was deleted.
Oops, something went wrong.
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,73 @@ | ||
import { task } from 'hardhat/config' | ||
import '@nomiclabs/hardhat-ethers' | ||
import * as fs from 'fs' | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types' | ||
import { selectors } from './lib' | ||
|
||
task('gen-selector-library', 'Generates a Solidity library with contract selectors for tests').setAction( | ||
async (_args, hre: HardhatRuntimeEnvironment) => { | ||
await hre.run('compile') | ||
|
||
// ridiculously, this appears to be the only way to get hardhat to compile a specific subtree | ||
// we are only updating the in-memory representation of the config, so it won't write this value out to disk | ||
// be careful if you compose this task with other tasks in larger scripts! | ||
hre.config.paths.sources = './test/mocks' | ||
await hre.run('compile') | ||
|
||
const contracts: string[] = [ | ||
'OwnershipFacet', | ||
'DiamondCutFacet', | ||
'DiamondLoupeFacet', | ||
'GatewayGetterFacet', | ||
'GatewayManagerFacet', | ||
'GatewayMessengerFacet', | ||
'CheckpointingFacet', | ||
'TopDownFinalityFacet', | ||
'XnetMessagingFacet', | ||
'SubnetActorGetterFacet', | ||
'SubnetActorManagerFacet', | ||
'SubnetActorPauseFacet', | ||
'SubnetActorRewardFacet', | ||
'SubnetActorCheckpointingFacet', | ||
'RegisterSubnetFacet', | ||
'SubnetGetterFacet', | ||
'SubnetActorMock', | ||
] | ||
|
||
const resolveSelectors = async (contractName: string) => { | ||
console.log(`Resolving selectors for ${contractName}...`) | ||
const artifact = await hre.artifacts.readArtifact(contractName) | ||
const iface = new hre.ethers.utils.Interface(artifact.abi) | ||
const encodedSelectors = hre.ethers.utils.defaultAbiCoder | ||
.encode(['bytes4[]'], [selectors({ interface: iface })]) | ||
.slice(2) | ||
return [contractName, encodedSelectors] | ||
} | ||
|
||
const allSelectors = Object.fromEntries(await Promise.all(contracts.map(resolveSelectors))) | ||
|
||
// Codegen. | ||
let code = `// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity ^0.8.19; | ||
library SelectorLibrary { | ||
function resolveSelectors(string memory facetName) public pure returns (bytes4[] memory facetSelectors) {` | ||
|
||
for (const [contractName, selector] of Object.entries(allSelectors)) { | ||
code += ` | ||
if (keccak256(abi.encodePacked(facetName)) == keccak256(abi.encodePacked("${contractName}"))) { | ||
return abi.decode(hex"${selector}", (bytes4[])); | ||
}` | ||
} | ||
|
||
code += ` | ||
revert(string.concat("Selectors not found for facet: ", facetName)); | ||
} | ||
} | ||
` | ||
// Write the generated code to a file. | ||
const outputPath = 'test/helpers/SelectorLibrary.sol' | ||
fs.writeFileSync(outputPath, code) | ||
console.log(`Selector library written to ${outputPath}`) | ||
}, | ||
) |
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
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
Oops, something went wrong.