Interest Rate Contract

The Interest Rate Contract is a critical component of the GasStation protocol responsible for calculating interest rates based on the total supply of GIX tokens, collateral, and gas prices. It determines the payouts for GIX holders and adjusts the system's cost rates. This contract provides interest rate logic for different chains, including ETH, Arbitrum (ARB), and Base.

Key Features

  • Interest Rate Calculation: Computes the interest rates for GIX tokens based on several factors such as gas price, time, and collateral.

  • Profit Margin and Annual Cost Rate Management: Configures the profit margins and annual cost rate parameters.

  • Chain-Specific Rate Calculation: Implements different interest rate logic for ETH, Arbitrum, and Base chains.

Functions

getInterestRate(uint256 totalShareSupply, uint256 gixTotalSupply, uint256 poolTotalCollateral, uint256 basefee, uint256 timeNow, uint256 timeLast)

Calculates the interest rate for GIX holders based on the total supply, collateral, and gas prices.

  • Parameters:

    • totalShareSupply: The total share supply of GIX.

    • gixTotalSupply: The total supply of GIX.

    • poolTotalCollateral: The total collateral in the pool.

    • basefee: The current base gas fee.

    • timeNow: The current timestamp.

    • timeLast: The timestamp of the last update.

  • Returns: A tuple containing:

    • result: The calculated interest rate.

    • profitLP: The profit for liquidity providers (LPs).

    • expectedPrice: The expected gas price.

interestRateETH(uint256 totalShareSupply, uint256 pc, uint256 pg, uint256 timeNow, uint256 timeLast)

Calculates the interest rate for ETH.

  • Parameters:

    • totalShareSupply: The total share supply of GIX.

    • pc: Collateral price.

    • pg: Gas price.

    • timeNow: The current timestamp.

    • timeLast: The timestamp of the last update.

  • Returns: The interest rate payout.

interestRateARB(uint256 totalShareSupply, uint256 pc, uint256 pg, uint256 timeNow, uint256 timeLast)

Calculates the interest rate for Arbitrum.

  • Parameters: Similar to interestRateETH.

  • Returns: The interest rate payout.

interestRateBASE(uint256 totalShareSupply, uint256 pc, uint256 pg, uint256 timeNow, uint256 timeLast)

Calculates the interest rate for Base.

  • Parameters: Similar to interestRateETH.

  • Returns: The interest rate payout.

calculateFirstTermETH(uint256 pg)

Calculates the first term used in the interest rate calculation for ETH.

  • Parameters:

    • pg: Gas price.

  • Returns: The result of the first term calculation.

calculateSecondTermETH(uint256 pc, uint256 pg)

Calculates the second term used in the interest rate calculation for ETH.

  • Parameters:

    • pc: Collateral price.

    • pg: Gas price.

  • Returns: The result of the second term calculation.

calculateFirstTermARB(uint256 pg)

Calculates the first term used in the interest rate calculation for Arbitrum.

  • Returns: The result of the first term calculation.

calculateSecondTermARB(uint256 pc, uint256 pg)

Calculates the second term used in the interest rate calculation for Arbitrum.

  • Returns: The result of the second term calculation.

calculateFirstTermBASE(uint256 pg)

Calculates the first term used in the interest rate calculation for Base.

  • Returns: The result of the first term calculation.

calculateSecondTermBASE(uint256 pc, uint256 pg)

Calculates the second term used in the interest rate calculation for Base.

  • Returns: The result of the second term calculation.

getBaseFeeFromTotalCollateral(uint256 poolTotalCollateral, uint256 totalSupply, uint256 basefee)

Calculates the base fee based on total collateral in the pool and total GIX supply.

  • Parameters:

    • poolTotalCollateral: Total collateral in the pool.

    • totalSupply: Total supply of GIX.

    • basefee: Base gas fee.

  • Returns: The base fee for the transaction.

getBaseFeeFromGIXCollateral(uint256 gixCollateralInPool, uint256 totalSupply, uint256 basefee)

Calculates the base fee based on GIX collateral in the pool and total GIX supply.

  • Returns: The base fee for the transaction.

Administrative Functions

changeProfitMargin(uint256 newAlphaNumerator, uint256 newAlphaDenominator)

Allows the owner to update the profit margin by changing the numerator and denominator of the profit margin formula.

  • Requirements:

    • Only callable by the owner.

  • Events: ProfitMarginChanged.

changeK(uint256 newK)

Allows the owner to change the K constant used in interest rate calculations.

  • Requirements:

    • Only callable by the owner.

  • Events: KChanged.

changeConstantAnnualCostRate(uint256 newValue)

Allows the owner to modify the constant annual cost rate.

  • Requirements:

    • Only callable by the owner.

  • Events: ConstantAnnualCostRateChanged.

Events

  • ProfitMarginChanged: Emitted when the profit margin parameters are updated.

  • KChanged: Emitted when the constant K is changed.

  • ConstantAnnualCostRateChanged: Emitted when the constant annual cost rate is modified.

Last updated