Skip to content

Latest commit

 

History

History
350 lines (293 loc) · 10.9 KB

FeeDistributor.md

File metadata and controls

350 lines (293 loc) · 10.9 KB

FeeDistributor.sol

View Source: contracts/FeeDistributor.sol

↗ Extends: CheckContract, FeeDistributorStorage, IFeeDistributor

FeeDistributor

Events

event SOVFeeCollectorAddressChanged(address  _sovFeeCollectorAddress);
event ZeroStakingAddressChanged(address  _zeroStakingAddress);
event BorrowerOperationsAddressChanged(address  _borrowerOperationsAddress);
event TroveManagerAddressChanged(address  _troveManagerAddress);
event WrbtcAddressChanged(address  _wrbtcAddress);
event ZUSDTokenAddressChanged(address  _zusdTokenAddress);
event ActivePoolAddressSet(address  _activePoolAddress);
event ZUSDDistributed(uint256  _zusdDistributedAmount);
event RBTCistributed(uint256  _rbtcDistributedAmount);

Functions


setAddresses

function setAddresses(address _sovFeeCollectorAddress, address _zeroStakingAddress, address _borrowerOperationsAddress, address _troveManagerAddress, address _wrbtcAddress, address _zusdTokenAddress, address _activePoolAddress) external nonpayable onlyOwner 

Arguments

Name Type Description
_sovFeeCollectorAddress address
_zeroStakingAddress address
_borrowerOperationsAddress address
_troveManagerAddress address
_wrbtcAddress address
_zusdTokenAddress address
_activePoolAddress address
Source Code
function setAddresses(
        address _sovFeeCollectorAddress,
        address _zeroStakingAddress,
        address _borrowerOperationsAddress,
        address _troveManagerAddress,
        address _wrbtcAddress,
        address _zusdTokenAddress,
        address _activePoolAddress
    ) external override onlyOwner {
        checkContract(_sovFeeCollectorAddress);
        checkContract(_zeroStakingAddress);
        checkContract(_borrowerOperationsAddress);
        checkContract(_troveManagerAddress);
        checkContract(_wrbtcAddress);
        checkContract(_zusdTokenAddress);
        checkContract(_activePoolAddress);

        sovFeeCollector = IFeeSharingProxy(_sovFeeCollectorAddress);
        zeroStaking = IZEROStaking(_zeroStakingAddress);
        borrowerOperations = IBorrowerOperations(_borrowerOperationsAddress);
        troveManager = ITroveManager(_troveManagerAddress);
        wrbtc = IWrbtc(_wrbtcAddress);
        zusdToken = IZUSDToken(_zusdTokenAddress);
        activePoolAddress = _activePoolAddress;

        // Not entirely removing this as per request from @light
        FEE_TO_SOV_COLLECTOR = LiquityMath.DECIMAL_PRECISION; // 100%

        emit SOVFeeCollectorAddressChanged(_sovFeeCollectorAddress);
        emit ZeroStakingAddressChanged(_zeroStakingAddress);
        emit BorrowerOperationsAddressChanged(_borrowerOperationsAddress);
        emit TroveManagerAddressChanged(_troveManagerAddress);
        emit WrbtcAddressChanged(_wrbtcAddress);
        emit ZUSDTokenAddressChanged(_zusdTokenAddress);
        emit ActivePoolAddressSet(_activePoolAddress);
    }

setFeeToSOVCollector

function setFeeToSOVCollector(uint256 FEE_TO_SOV_COLLECTOR_) public nonpayable onlyOwner 

Arguments

Name Type Description
FEE_TO_SOV_COLLECTOR_ uint256
Source Code
function setFeeToSOVCollector(uint256 FEE_TO_SOV_COLLECTOR_) public onlyOwner {
        FEE_TO_SOV_COLLECTOR = FEE_TO_SOV_COLLECTOR_;
    }

distributeFees

function distributeFees() public nonpayable
Source Code
function distributeFees() public override {
        require(
            msg.sender == address(borrowerOperations) || msg.sender == address(troveManager),
            "FeeDistributor: invalid caller"
        );
        uint256 zusdtoDistribute = zusdToken.balanceOf(address(this));
        uint256 rbtcToDistribute = address(this).balance;
        if (zusdtoDistribute != 0) {
            _distributeZUSD(zusdtoDistribute);
        }
        if (rbtcToDistribute != 0) {
            _distributeRBTC(rbtcToDistribute);
        }
    }

_distributeZUSD

function _distributeZUSD(uint256 toDistribute) internal nonpayable

Arguments

Name Type Description
toDistribute uint256
Source Code
function _distributeZUSD(uint256 toDistribute) internal {
        // Send fee to the SOVFeeCollector address
        uint256 feeToSovCollector = toDistribute.mul(FEE_TO_SOV_COLLECTOR).div(
            LiquityMath.DECIMAL_PRECISION
        );
        zusdToken.approve(address(sovFeeCollector), feeToSovCollector);
        sovFeeCollector.transferTokens(address(zusdToken), uint96(feeToSovCollector));

        // Send fee to ZERO staking contract
        uint256 feeToZeroStaking = toDistribute.sub(feeToSovCollector);
        if (feeToZeroStaking != 0) {
            require(
                zusdToken.transfer(address(zeroStaking), feeToZeroStaking),
                "Coudn't execute ZUSD transfer"
            );
            zeroStaking.increaseF_ZUSD(feeToZeroStaking);
        }
        emit ZUSDDistributed(toDistribute);
    }

_distributeRBTC

function _distributeRBTC(uint256 toDistribute) internal nonpayable

Arguments

Name Type Description
toDistribute uint256
Source Code
function _distributeRBTC(uint256 toDistribute) internal {
        // Send fee to the SOVFeeCollector address
        uint256 feeToSovCollector = toDistribute.mul(FEE_TO_SOV_COLLECTOR).div(
            LiquityMath.DECIMAL_PRECISION
        );
        wrbtc.deposit{value: feeToSovCollector}();
        wrbtc.approve(address(sovFeeCollector), feeToSovCollector);
        sovFeeCollector.transferTokens(address(wrbtc), uint96(feeToSovCollector));

        // Send the ETH fee to the ZERO staking contract
        uint256 feeToZeroStaking = toDistribute.sub(feeToSovCollector);
        if (feeToZeroStaking != 0) {
            (bool success, ) = address(zeroStaking).call{value: feeToZeroStaking}("");
            require(success, "FeeDistributor: sending ETH failed");
            zeroStaking.increaseF_ETH(feeToZeroStaking);
        }
        emit RBTCistributed(toDistribute);
    }

_requireCallerIsActivePool

function _requireCallerIsActivePool() internal view
Source Code
function _requireCallerIsActivePool() internal view {
        require(msg.sender == activePoolAddress, "FeeDistributor: caller is not ActivePool");
    }

constructor

function () external payable
Source Code
receive() external payable {
        _requireCallerIsActivePool();
    }

Contracts