A Solidity contracts library for interacting with stateful-precompiled contract.
The @kiwarilabs/stateful-contracts library empowers smart contract developers to build customized, adaptive blockchain networks that meet the demands of regulated finance, decentralized infrastructure, and sustainable on-chain economies—all while maintaining Ethereum compatibility.
With stateful-precompiled contracts, developers can achieve dynamic control over blockchain components at runtime, without requiring forks or node configuration updates. This unlocks new possibilities for:
- Build a regulated blockchain for payment because you can mint the native token at
runtime. - Build a blockchain with a revenue-shared model with
RevenueRatioprecompiled. - Trusted Network of Internet of Things (IoT) or Decentralized Infrastructure Network (DePIN) with
AddressRegistryprecompiled. - Building
AddressRegistryprecompiled as a shared registry for general purposes such as Know Your Customer (KYC) or Blacklist. - Write a
gasSchedulingprogram for adjusting thegasPrice. - Write an
adaptiveGasPricemechanism when some states from other contracts meet the condition. - Write any logic to calculate the
gasPricethen you set the runtimegasPriceviaGasPriceprecompiled. - Sponsor
gas, enabling users to transact without fees viaGasFeeGrantlike cosmos-sdk/feegrant module.
npm install @kiwarilabs/stateful-contractsClone repository
git clone https://github.com/Kiwari-Labs/stateful-contractsInstalling dependencies
yarn installBuilding the package locally
yarn run packInstalling local build package to your project with yarn please see this document.
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import {AbstractNativeMinter} from "@kiwarilabs/abstracts/AbstractNativeMinter.sol";
import {AbstractAddressRegistry} from "@kiwarilabs/abstracts/AbstractAddressRegistry.sol";
import {AbstractGasPrice} from "@kiwarilabs/abstracts/AbstractGasPrice.sol";
import {AbstractRevenueRatio} from "@kiwarilabs/abstracts/AbstractRevenueRatio.sol";
import {AbstractTreasuryRegistry} from "@kiwarilabs/abstracts/AbstractTreasuryRegistry.sol";
import {AbstractGasFeeGrant} from "@kiwarilabs/abstracts/AbstractGasFeeGrant.sol";
contract RuntimeControlContract is AbstractNativeMinter, AbstractAddressRegistry, AbstractGasPrice, AbstractRevenueRatio, AbstractTreasuryRegistry, AbstractGasFeeGrant {
constructor(
address nativeMinterPrecompiled,
address addressRegistryPrecompiled,
address gasPricePrecompiled,
address revenueRatioPrecompiled,
address treasuryRegistryPrecompiled,
address gasFeeGrantPrecompiled,
address admin
)
AbstractNativeMinter(nativeMinterPrecompiled, admin)
AbstractAddressRegistry(addressRegistryPrecompiled, admin)
AbstractGasPrice(gasPricePrecompiled, admin)
AbstractRevenueRatio(revenueRatioPrecompiled, admin)
AbstractTreasuryRegistry(treasuryRegistryPrecompiled, admin)
AbstractGasFeeGrant(gasFeeGrantPrecompiled, admin)
{}
// Your implementation below, e.g governance vote before action.
}Please change the image in docker-compose.yml to the Kiwari-Labs/besu image.
cd blockchainFor starting the network
./scripts/start.shFor stop the network
./scripts/stop.shImportant
If you don't want to use stateful precompiled contracts, you can initial owner with address(0) at genesis.json or call initializedOwner with address(0).
- Stateful-precompiled contract imploded EIP-1352 for reserve system contract address.
contract address NativeMinterContract0x0000000000000000000000000000000000001001AddressRegistryContract0x0000000000000000000000000000000000001002GasPriceContract0x0000000000000000000000000000000000001003RevenueRatioContract0x0000000000000000000000000000000000001004TreasuryRegistryContract0x0000000000000000000000000000000000001005GasFeeGrantContract0x0000000000000000000000000000000000001006
- Each stateful-precompiled contract adopts the
Ownablepattern for access control and can beinitializeOwneronly once before usage. - The
gasUsedfor a precompiled operation in the mock contract differs from the actual precompiled contract, as the actualgasUseddepends on its specific implementation. TheNativeMinterandcontractRatioofRevenueRatioshould be used with caution. If the minting native token or the transaction fee is distributed back to the Liquidity Pool, it may affect the trading pair. - The
GasFeeGrantwill not function if thegranter's balance is insufficient to cover thegrantee's transaction fees. - The
GasFeeGrantdoes not automatically adjust thegasPriceof the transaction to match the mediangasPrice.- If the grantee has a
PERIODIC_ALLOWANCEand submits a transaction with an excessively highgasPrice, it may quickly deplete the allocated fee allowance for that period. - For
BASIC_ALLOWANCE, avoid setting an excessively highfeeGrantPerTransaction, as a single transaction could consume the entire granter balance. - In all cases, avoid setting high values for
expiredAt,feeGrantPerTransaction, andfeeGrantPerPeriodto minimize the risk of stale grants being exploited.
- If the grantee has a
Copyright 2025 Kiwari Labs and Advanced Info Services PLC Licensed under the MIT.