跳转到主要内容

参数

此方法不接受任何参数。

响应

result
object

代码示例

基本请求

curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getInflationGovernor"
}'

使用 web3.js

import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

// Get inflation governor parameters
const inflationGovernor = await connection.getInflationGovernor();
console.log('Initial inflation:', inflationGovernor.initial);
console.log('Terminal inflation:', inflationGovernor.terminal);
console.log('Taper rate:', inflationGovernor.taper);
console.log('Foundation percentage:', inflationGovernor.foundation);
console.log('Foundation term:', inflationGovernor.foundationTerm);

// Calculate current inflation rate
async function calculateCurrentInflation() {
  const inflationGovernor = await connection.getInflationGovernor();
  const epochInfo = await connection.getEpochInfo();
  
  const yearsSinceGenesis = epochInfo.absoluteSlot / (432000 * 365); // Approximate years
  const currentInflation = Math.max(
    inflationGovernor.terminal,
    inflationGovernor.initial - (inflationGovernor.taper * yearsSinceGenesis)
  );
  
  return {
    currentInflation,
    yearsSinceGenesis,
    initialInflation: inflationGovernor.initial,
    terminalInflation: inflationGovernor.terminal,
    taperRate: inflationGovernor.taper
  };
}

注意事项

  1. 返回管理 Solana 网络通胀的参数
  2. 通胀随时间按递减率降低
  3. 基金会通胀与验证者通胀是分开的
  4. 响应是即时的,因为它从当前状态读取
  5. 这些参数由治理设置,可能会改变

最佳实践

  1. 使用此方法了解网络的通胀计划
  2. 在适当时缓存结果以减少 RPC 负载
  3. 考虑通胀对质押奖励的影响
  4. 监控通胀参数的变化
  5. 结合其他通胀相关方法使用

常见错误

错误码消息解决方案
-32601Method not found验证是否连接到 Solana RPC 节点
-32007Inflation information unavailable节点可能正在启动或同步中

用例

  1. 通胀分析
    interface InflationMetrics {
      currentInflation: number;
      yearsSinceGenesis: number;
      initialInflation: number;
      terminalInflation: number;
      taperRate: number;
      foundationPercentage: number;
      foundationTerm: number;
      validatorInflation: number;
      foundationInflation: number;
    }
    
    async function analyzeInflation(): Promise<InflationMetrics> {
      const inflationGovernor = await connection.getInflationGovernor();
      const epochInfo = await connection.getEpochInfo();
      
      const yearsSinceGenesis = epochInfo.absoluteSlot / (432000 * 365);
      const currentInflation = Math.max(
        inflationGovernor.terminal,
        inflationGovernor.initial - (inflationGovernor.taper * yearsSinceGenesis)
      );
      
      const foundationInflation = yearsSinceGenesis < inflationGovernor.foundationTerm
        ? currentInflation * inflationGovernor.foundation
        : 0;
      
      return {
        currentInflation,
        yearsSinceGenesis,
        initialInflation: inflationGovernor.initial,
        terminalInflation: inflationGovernor.terminal,
        taperRate: inflationGovernor.taper,
        foundationPercentage: inflationGovernor.foundation,
        foundationTerm: inflationGovernor.foundationTerm,
        validatorInflation: currentInflation - foundationInflation,
        foundationInflation
      };
    }
    
  2. 质押奖励预测
    interface StakingProjection {
      currentAPY: number;
      futureAPY: number[];
      years: number[];
    }
    
    async function projectStakingRewards(
      totalStaked: number,
      totalSupply: number,
      years: number = 10
    ): Promise<StakingProjection> {
      const inflationGovernor = await connection.getInflationGovernor();
      const epochInfo = await connection.getEpochInfo();
      
      const currentYear = epochInfo.absoluteSlot / (432000 * 365);
      const yearsArray = Array.from({ length: years }, (_, i) => i);
      
      const futureAPY = yearsArray.map(year => {
        const inflation = Math.max(
          inflationGovernor.terminal,
          inflationGovernor.initial - (inflationGovernor.taper * (currentYear + year))
        );
        
        const foundationInflation = (currentYear + year) < inflationGovernor.foundationTerm
          ? inflation * inflationGovernor.foundation
          : 0;
        
        const validatorInflation = inflation - foundationInflation;
        return (validatorInflation * totalSupply) / totalStaked;
      });
      
      return {
        currentAPY: futureAPY[0],
        futureAPY,
        years: yearsArray
      };
    }
    
  3. 通胀监控
    interface InflationAlert {
      type: 'high' | 'low' | 'change';
      message: string;
      currentInflation: number;
      expectedInflation: number;
      difference: number;
    }
    
    async function monitorInflation(
      threshold: number = 0.01
    ): Promise<InflationAlert[]> {
      const inflationGovernor = await connection.getInflationGovernor();
      const epochInfo = await connection.getEpochInfo();
      
      const yearsSinceGenesis = epochInfo.absoluteSlot / (432000 * 365);
      const expectedInflation = Math.max(
        inflationGovernor.terminal,
        inflationGovernor.initial - (inflationGovernor.taper * yearsSinceGenesis)
      );
      
      const currentInflation = await connection.getInflationRate();
      const difference = Math.abs(currentInflation - expectedInflation);
      
      const alerts: InflationAlert[] = [];
      
      if (difference > threshold) {
        alerts.push({
          type: 'change',
          message: `Inflation differs from expected by ${difference.toFixed(4)}`,
          currentInflation,
          expectedInflation,
          difference
        });
      }
      
      if (currentInflation > inflationGovernor.initial) {
        alerts.push({
          type: 'high',
          message: `Inflation is above initial rate`,
          currentInflation,
          expectedInflation,
          difference
        });
      }
      
      if (currentInflation < inflationGovernor.terminal) {
        alerts.push({
          type: 'low',
          message: `Inflation is below terminal rate`,
          currentInflation,
          expectedInflation,
          difference
        });
      }
      
      return alerts;
    }