-
Notifications
You must be signed in to change notification settings - Fork 83
/
StakingFormulasFacet.sol
109 lines (103 loc) · 3.89 KB
/
StakingFormulasFacet.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {LibStakingFormulas} from "../libraries/LibStakingFormulas.sol";
import {StakingShare} from "../core/StakingShare.sol";
import "../interfaces/IUbiquityFormulas.sol";
/// @notice Contract facet staking formulas
contract StakingFormulasFacet is IUbiquityFormulas {
/**
* @notice Formula of governance rights corresponding to a staking shares LP amount
* @notice Used on removing liquidity from staking
* @notice `shares = (stake.shares * _amount) / stake.lpAmount`
* @param _stake Stake info of staking share
* @param _shareInfo Array of share amounts
* @param _amount Amount of LP tokens
* @return _uLP Amount of shares
*/
function sharesForLP(
StakingShare.Stake memory _stake,
uint256[2] memory _shareInfo,
uint256 _amount
) external pure returns (uint256 _uLP) {
return LibStakingFormulas.sharesForLP(_stake, _shareInfo, _amount);
}
/**
* @notice Formula may add a decreasing rewards if locking end is near when removing liquidity
* @notice `rewards = _amount`
* @param _stake Stake info of staking share
* @param _shareInfo Array of share amounts
* @param _amount Amount of LP tokens
* @return Amount of LP rewards
*/
function lpRewardsRemoveLiquidityNormalization(
StakingShare.Stake memory _stake,
uint256[2] memory _shareInfo,
uint256 _amount
) external pure returns (uint256) {
return
LibStakingFormulas.lpRewardsRemoveLiquidityNormalization(
_stake,
_shareInfo,
_amount
);
}
/**
* @notice Formula may add a decreasing rewards if locking end is near when adding liquidity
* @notice `rewards = _amount`
* @param _stake Stake info of staking share
* @param _shareInfo Array of share amounts
* @param _amount Amount of LP tokens
* @return Amount of LP rewards
*/
function lpRewardsAddLiquidityNormalization(
StakingShare.Stake memory _stake,
uint256[2] memory _shareInfo,
uint256 _amount
) external pure returns (uint256) {
return
LibStakingFormulas.lpRewardsAddLiquidityNormalization(
_stake,
_shareInfo,
_amount
);
}
/**
* @notice Formula to calculate the corrected amount to withdraw based on the proportion of
* LP deposited against actual LP tokens in the staking contract
* @notice `corrected_amount = amount * (stakingLpBalance / totalLpDeposited)`
* @notice If there is more or the same amount of LP than deposited then do nothing
* @param _totalLpDeposited Total amount of LP deposited by users
* @param _stakingLpBalance Actual staking contract LP tokens balance minus LP rewards
* @param _amount Amount of LP tokens
* @return Amount of LP tokens to redeem
*/
function correctedAmountToWithdraw(
uint256 _totalLpDeposited,
uint256 _stakingLpBalance,
uint256 _amount
) external pure returns (uint256) {
return
LibStakingFormulas.correctedAmountToWithdraw(
_totalLpDeposited,
_stakingLpBalance,
_amount
);
}
/**
* @notice Formula duration multiply
* @notice `_shares = (1 + _multiplier * _weeks^3/2) * _uLP`
* @notice `D32 = D^3/2`
* @notice `S = m * D32 * A + A`
* @param _uLP Amount of LP tokens
* @param _weeks Minimum duration of staking period
* @param _multiplier Staking discount multiplier = 0.0001
* @return _shares Amount of shares
*/
function durationMultiply(
uint256 _uLP,
uint256 _weeks,
uint256 _multiplier
) external pure returns (uint256 _shares) {
return LibStakingFormulas.durationMultiply(_uLP, _weeks, _multiplier);
}
}