all files / plugins/assets/convex/vendor/ CvxMining.sol

0% Statements 0/11
0% Branches 0/4
0% Functions 0/1
0% Lines 0/13
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                                                                                     
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
 
interface ICvx {
    function reductionPerCliff() external view returns (uint256);
 
    function totalSupply() external view returns (uint256);
 
    function totalCliffs() external view returns (uint256);
 
    function maxSupply() external view returns (uint256);
}
 
library CvxMining {
    ICvx public constant cvx = ICvx(0x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B);
 
    function ConvertCrvToCvx(uint256 _amount) external view returns (uint256) {
        uint256 supply = cvx.totalSupply();
        uint256 reductionPerCliff = cvx.reductionPerCliff();
        uint256 totalCliffs = cvx.totalCliffs();
        uint256 maxSupply = cvx.maxSupply();
 
        uint256 cliff = supply / reductionPerCliff;
        //mint if below total cliffs
        if (cliff < totalCliffs) {
            //for reduction% take inverse of current cliff
            uint256 reduction = totalCliffs - cliff;
            //reduce
            _amount = (_amount * reduction) / totalCliffs;
 
            //supply cap check
            uint256 amtTillMax = maxSupply - supply;
            if (_amount > amtTillMax) {
                _amount = amtTillMax;
            }
 
            //mint
            return _amount;
        }
        return 0;
    }
}