BPSFeed.sol

Overview

The BPSFeed contract is designed to maintain a weighted feed of Basis Points (BPS). It is a simple contract that maintains a rate and updates it over time.

Key Features

  • Provides a method for getting the weighted rate.

  • Allows the owner (Protocol MultiSig) to update the rate.

Core Parameters

The contract maintains the following state variables:

  • currentRate: The current Basis Points (BPS) rate.

  • lastTimestamp: The timestamp when the rate was last updated.

  • _totalRate: The internal state variable to store the sum of all previously recorded rates.

  • _totalDuration: The internal state variable to store the total duration over which the rates have been recorded.

Modifiers

  • onlyOwner: A modifier provided by the Owned library that restricts function execution to the contract owner only.

Functions

The contract provides the following main functions:

  • getWeightedRate: This function computes the average BPS rate over time. If no previous rate is stored, it returns 0. Otherwise, it calculates the weighted rate as the sum of all rates (including the current one, weighted by the duration since the last update) divided by the total duration.

  • updateRate: This function, which can only be called by the contract owner, updates the current BPS rate. If a previous rate exists, it updates the total rate and total duration by adding the product of the current rate and the duration since the last update. It then sets the new current rate and updates the lastTimestamp.

Last updated