The contract stores information about different pools in the
poolInfoPrivatemapping. Each pool has an ID and is associated with certain information, such as its type, staking rules, and the start and end times for staking. There are three pool types in the contract each have separate parameters. This allows for both variable and stable interest rates.
The contract uses the
calculateInterestfunction to calculate the interest that a user will earn from staking their tokens in a specific pool for a specified duration. The function starts by looking up the information for the specified pool in the
poolInfoPrivatemapping. The function then calculates the utilization of the pool, which is a measure of how much of the pool is being used. If the pool is of type
ConstrainedLoan, the utilization is set to 100%. If the pool is of type
Loan, the utilization is obtained by calling the
getPoolUtilisationfunction. Then the function calculates the interest earned by the user by multiplying the amount staked, the annual percentage yield (APY), the utilization, and the duration and then dividing the result by a precision factor. The precision factor takes into account the different units of measure used for the APY and the duration. The function returns the calculated interest as the result.
APY = (Staked Amount * APY rate * Utilization * Duration) / (100 * 100 * 1 Year * Precision Factor)
- Staked Amount is the amount of tokens being staked
- APY rate is the annual interest rate for the pool
- Utilization is the utilization of the pool
- Duration is the length of time that the tokens will be staked for
- Precision Factor takes into account the different units of measure used for the APY and the duration
Note: The formula assumes the use of specific units for the APY rate, duration, and precision factor, which are all defined in the code.
Example: if you were to stake 100 USDC for 1 year in a pool with a 10% annual percentage yield (APY) and 100% utilization, this code would calculate the interest earned as 10 USDC. The calculation takes into account the different units of measure used for the APY and duration to come up with an accurate result.