This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
GaugePointFacet.sol
58 lines (51 loc) · 1.87 KB
/
GaugePointFacet.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* SPDX-License-Identifier: MIT
*/
pragma solidity =0.7.6;
pragma experimental ABIEncoderV2;
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
import {LibGauge} from "contracts/libraries/LibGauge.sol";
/**
* @title GaugePointFacet
* @author Brean
* @notice Calculates the gaugePoints for whitelisted Silo LP tokens.
*/
contract GaugePointFacet {
using SafeMath for uint256;
uint256 private constant ONE_POINT = 1e18;
uint256 private constant MAX_GAUGE_POINTS = 1000e18;
uint256 private constant UPPER_THRESHOLD = 10001;
uint256 private constant LOWER_THRESHOLD = 9999;
uint256 private constant THRESHOLD_PRECISION = 10000;
/**
* @notice DefaultGaugePointFunction
* is the default function to calculate the gauge points
* of an LP asset.
*
* @dev If % of deposited BDV is .01% within range of optimal,
* keep gauge points the same.
*
* Cap gaugePoints to MAX_GAUGE_POINTS to avoid runaway gaugePoints.
*/
function defaultGaugePointFunction(
uint256 currentGaugePoints,
uint256 optimalPercentDepositedBdv,
uint256 percentOfDepositedBdv
) external pure returns (uint256 newGaugePoints) {
if (
percentOfDepositedBdv >
optimalPercentDepositedBdv.mul(UPPER_THRESHOLD).div(THRESHOLD_PRECISION)
) {
// gauge points cannot go below 0.
if (currentGaugePoints <= ONE_POINT) return 0;
newGaugePoints = currentGaugePoints.sub(ONE_POINT);
} else if (
percentOfDepositedBdv <
optimalPercentDepositedBdv.mul(LOWER_THRESHOLD).div(THRESHOLD_PRECISION)
) {
newGaugePoints = currentGaugePoints.add(ONE_POINT);
// Cap gaugePoints to MAX_GAUGE_POINTS if it exceeds.
if (newGaugePoints > MAX_GAUGE_POINTS) return MAX_GAUGE_POINTS;
}
}
}