github.com/MetalBlockchain/subnet-evm@v0.4.9/contract-examples/contracts/ExampleFeeManager.sol (about)

     1  //SPDX-License-Identifier: MIT
     2  pragma solidity ^0.8.0;
     3  pragma experimental ABIEncoderV2;
     4  
     5  import "@openzeppelin/contracts/access/Ownable.sol";
     6  import "./AllowList.sol";
     7  import "./IFeeManager.sol";
     8  
     9  // ExampleFeeManager shows how FeeConfigManager precompile can be used in a smart contract
    10  // All methods of [allowList] can be directly called. There are example calls as tasks in hardhat.config.ts file.
    11  contract ExampleFeeManager is AllowList {
    12    // Precompiled Fee Manager Contract Address
    13    address constant FEE_MANAGER_ADDRESS = 0x0200000000000000000000000000000000000003;
    14    IFeeManager feeManager = IFeeManager(FEE_MANAGER_ADDRESS);
    15  
    16    struct FeeConfig {
    17      uint256 gasLimit;
    18      uint256 targetBlockRate;
    19      uint256 minBaseFee;
    20      uint256 targetGas;
    21      uint256 baseFeeChangeDenominator;
    22      uint256 minBlockGasCost;
    23      uint256 maxBlockGasCost;
    24      uint256 blockGasCostStep;
    25    }
    26  
    27    constructor() AllowList(FEE_MANAGER_ADDRESS) {}
    28  
    29    function enableWAGMIFees() public onlyEnabled {
    30      feeManager.setFeeConfig(
    31        20_000_000, // gasLimit
    32        2, // targetBlockRate
    33        1_000_000_000, // minBaseFee
    34        100_000_000, // targetGas
    35        48, // baseFeeChangeDenominator
    36        0, // minBlockGasCost
    37        10_000_000, // maxBlockGasCost
    38        500_000 // blockGasCostStep
    39      );
    40    }
    41  
    42    function enableCChainFees() public onlyEnabled {
    43      feeManager.setFeeConfig(
    44        8_000_000, // gasLimit
    45        2, // targetBlockRate
    46        25_000_000_000, // minBaseFee
    47        15_000_000, // targetGas
    48        36, // baseFeeChangeDenominator
    49        0, // minBlockGasCost
    50        1_000_000, // maxBlockGasCost
    51        200_000 // blockGasCostStep
    52      );
    53    }
    54  
    55    function enableCustomFees(FeeConfig memory config) public onlyEnabled {
    56      feeManager.setFeeConfig(
    57        config.gasLimit,
    58        config.targetBlockRate,
    59        config.minBaseFee,
    60        config.targetGas,
    61        config.baseFeeChangeDenominator,
    62        config.minBlockGasCost,
    63        config.maxBlockGasCost,
    64        config.blockGasCostStep
    65      );
    66    }
    67  
    68    function getCurrentFeeConfig() public view returns (FeeConfig memory) {
    69      FeeConfig memory config;
    70      (
    71        config.gasLimit,
    72        config.targetBlockRate,
    73        config.minBaseFee,
    74        config.targetGas,
    75        config.baseFeeChangeDenominator,
    76        config.minBlockGasCost,
    77        config.maxBlockGasCost,
    78        config.blockGasCostStep
    79      ) = feeManager.getFeeConfig();
    80      return config;
    81    }
    82  
    83    function getFeeConfigLastChangedAt() public view returns (uint256) {
    84      return feeManager.getFeeConfigLastChangedAt();
    85    }
    86  }