@dappsoverapps.com/hardhat-patch
v0.1.2
Published
Hardhat plugin for Arbitrum precompile support
Maintainers
Readme
@dappsoverapps.com/hardhat-patch
A Hardhat plugin that adds native support for Arbitrum precompiles to local development networks.
Features
- ArbSys Precompile (0x64): System-level utilities for L1↔L2 interactions
- ArbGasInfo Precompile (0x6C): Gas pricing and L1 cost estimation
- Modular Registry: Easy to add new precompile handlers
- Configurable: Customize chain ID, ArbOS version, and gas pricing
Installation
npm install @dappsoverapps.com/hardhat-patchUsage
Basic Setup
// hardhat.config.ts
import { HardhatUserConfig } from "hardhat/config";
const config: HardhatUserConfig = {
solidity: "0.8.19",
networks: {
hardhat: {
// Enable Arbitrum features
arbitrum: {
enabled: true,
chainId: 42161, // Arbitrum One
arbOSVersion: 20,
},
},
},
};
export default config;Custom Configuration
const config: HardhatUserConfig = {
solidity: "0.8.19",
networks: {
hardhat: {
arbitrum: {
enabled: true,
chainId: 421613, // Arbitrum Goerli
arbOSVersion: 21,
l1BaseFee: BigInt(15e9), // 15 gwei
gasPriceComponents: {
l2BaseFee: BigInt(2e9), // 2 gwei
l1CalldataCost: BigInt(20), // 20 gas per byte
l1StorageCost: BigInt(0),
congestionFee: BigInt(1e8), // 0.1 gwei
},
},
},
},
};Programmatic Usage
import { HardhatArbitrumPatch } from "@dappsoverapps.com/hardhat-patch";
// Create plugin instance
const arbitrumPatch = new HardhatArbitrumPatch({
chainId: 42161,
arbOSVersion: 20,
});
// Access the registry
const registry = arbitrumPatch.getRegistry();
// Check if a precompile is supported
if (arbitrumPatch.hasHandler("0x0000000000000000000000000000000000000064")) {
console.log("ArbSys precompile is available");
}
// List all handlers
const handlers = arbitrumPatch.listHandlers();
console.log(
"Available precompiles:",
handlers.map((h) => h.name)
);Supported Precompiles
ArbSys (0x64)
arbChainID()- Returns the Arbitrum chain IDarbBlockNumber()- Returns the current L2 block numberarbBlockHash(uint256)- Returns block hash for given block numberarbOSVersion()- Returns the current ArbOS version
ArbGasInfo (0x6C)
getPricesInWei()- Returns 5-tuple of gas price componentsgetL1BaseFeeEstimate()- Returns estimated L1 base feegetCurrentTxL1GasFees()- Returns L1 gas fees for current transactiongetPricesInArbGas()- Returns 3-tuple in ArbGas units
Development
Building
npm run buildTesting
npm testLinting
npm run lintArchitecture
The plugin uses a modular registry system:
- Registry Interface: Defines the contract for precompile handlers
- Handler Implementation: Each precompile has its own handler class
- Plugin Integration: Automatically registers handlers on Hardhat startup
- Configuration: Supports customization of key parameters
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT
