Skip to content

Commit

Permalink
Donate ERC20 fund to Vault
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Jan 20, 2024
1 parent eaf4ae1 commit ce7f8ee
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
55 changes: 30 additions & 25 deletions contracts/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity ^0.8.0;

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IVault} from "./interfaces/IVault.sol";
import {IRewardsDistributor} from "./interfaces/IRewardsDistributor.sol";
import {IVoter} from "./interfaces/IVoter.sol";
Expand All @@ -11,9 +13,13 @@ import {IVotingEscrow} from "./interfaces/IVotingEscrow.sol";
/// @author velodrome.finance, @figs999, @pegahcarter
/// @notice Controls minting of emissions and rebases for the Protocol
contract Vault is IVault {
using SafeERC20 for IERC20;

/// @inheritdoc IVault
IVoter public immutable voter;
/// @inheritdoc IVault
address public governor;
/// @inheritdoc IVault
IVotingEscrow public immutable ve;
/// @inheritdoc IVault
IRewardsDistributor public immutable rewardsDistributor;
Expand All @@ -28,10 +34,6 @@ contract Vault is IVault {
uint256 public activePeriod;
/// @inheritdoc IVault
uint256 public epochCount;
/// @inheritdoc IVault
address public team;
/// @inheritdoc IVault
address public pendingTeam;

constructor(
address _voter, // the voting & distribution system
Expand All @@ -40,24 +42,16 @@ contract Vault is IVault {
) {
voter = IVoter(_voter);
ve = IVotingEscrow(_ve);
team = msg.sender;
governor = msg.sender;
rewardsDistributor = IRewardsDistributor(_rewardsDistributor);
activePeriod = ((block.timestamp) / WEEK) * WEEK; // allow emissions this coming epoch
}

/// @inheritdoc IVault
function setTeam(address _team) external {
if (msg.sender != team) revert NotTeam();
if (_team == address(0)) revert ZeroAddress();
pendingTeam = _team;
}

/// @inheritdoc IVault
function acceptTeam() external {
if (msg.sender != pendingTeam) revert NotPendingTeam();
team = pendingTeam;
delete pendingTeam;
emit AcceptTeam(team);
function setGovernor(address _governor) public {
if (msg.sender != governor) revert NotGovernor();
if (_governor == address(0)) revert ZeroAddress();
governor = _governor;
}

/// @inheritdoc IVault
Expand Down Expand Up @@ -86,35 +80,46 @@ contract Vault is IVault {

/// @inheritdoc IVault
function changeWeekly(uint256 _weekly) external {
if (msg.sender != team) revert NotTeam();
if (msg.sender != governor) revert NotGovernor();

weekly = _weekly;
emit WeeklyChanged(_weekly);
}

/// @inheritdoc IVault
function changeVeRate(uint256 _rate) external {
if (msg.sender != team) revert NotTeam();
if (msg.sender != governor) revert NotGovernor();
if (_rate > 5000) revert InvalidRate();

veRate = _rate;
emit VeRateChanged(_rate);
}

/// @inheritdoc IVault
function withdraw(address payable _recipcient, uint256 _amount) external {
if (msg.sender != team) revert NotTeam();
_recipcient.transfer(_amount);
emit Withdraw(msg.sender, _recipcient, _amount);
function withdraw(address _token, address payable _recipcient, uint256 _amount) external {
if (msg.sender != governor) revert NotGovernor();

if (_token == address(0)) {
_recipcient.transfer(_amount);
} else {
IERC20(_token).safeTransfer(_recipcient, _amount);
}
emit Withdraw(msg.sender, _token, _recipcient, _amount);
}

receive() external payable {
emit Donation(msg.sender, msg.value);
emit Donation(msg.sender, address(0), msg.value);
}

/// @inheritdoc IVault
function donate() external payable {
if (msg.value == 0) revert ZeroDonation();
emit Donation(msg.sender, msg.value);
emit Donation(msg.sender, address(0), msg.value);
}

/// @inheritdoc IVault
function donate(address _token, uint256 _amount) external {
IERC20(_token).safeTransferFrom(msg.sender, address(this), _amount);
emit Donation(msg.sender, _token, _amount);
}
}
37 changes: 16 additions & 21 deletions contracts/interfaces/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ import {IVotingEscrow} from "./IVotingEscrow.sol";
import {IRewardsDistributor} from "./IRewardsDistributor.sol";

interface IVault {
error NotTeam();
error NotGovernor();
error ZeroAddress();
error ZeroDonation();
error InvalidRate();
error NotPendingTeam();
error InsufficientFund();

event Emission(address indexed sender, uint256 weekly);
event AcceptTeam(address indexed _newTeam);
event WeeklyChanged(uint256 weekly);
event VeRateChanged(uint256 rate);
event Donation(address indexed donor, uint256 amount);
event Withdraw(address indexed operator, address indexed recipcient, uint256 amount);
event Donation(address indexed donor, address indexed token, uint256 amount);
event Withdraw(address indexed operator, address indexed token, address indexed recipcient, uint256 amount);

/// @notice Interface of Voter.sol
function voter() external view returns (IVoter);

/// @notice Standard OZ IGovernor using ve for vote weights.
function governor() external view returns (address);

/// @notice Interface of IVotingEscrow.sol
function ve() external view returns (IVotingEscrow);

Expand All @@ -44,20 +45,6 @@ interface IVault {
/// @notice Number of epochs in which updatePeriod was called
function epochCount() external view returns (uint256);

/// @notice Current team address in charge of emissions
function team() external view returns (address);

/// @notice Possible team address pending approval of current team
function pendingTeam() external view returns (address);

/// @notice Creates a request to change the current team's address
/// @param _team Address of the new team to be chosen
function setTeam(address _team) external;

/// @notice Accepts the request to replace the current team's address
/// with the requested one, present on variable pendingTeam
function acceptTeam() external;

/// @notice Processes emissions and rebases. Callable once per epoch (1 week).
/// @return _period Start of current epoch.
function updatePeriod() external returns (uint256 _period);
Expand All @@ -69,8 +56,16 @@ interface IVault {
function changeVeRate(uint256 _rate) external;

/// @notice Withdraw fund from DAO
function withdraw(address payable _recipcient, uint256 _amount) external;
function withdraw(address _token, address payable _recipcient, uint256 _amount) external;

/// @notice Set new governor.
/// @dev Throws if not called by governor.
/// @param _governor .
function setGovernor(address _governor) external;

/// @notice Donate fund to DAO
/// @notice Donate native fund to DAO
function donate() external payable;

/// @notice Donate ERC20 fund to DAO
function donate(address _token, uint256 _amount) external;
}
1 change: 0 additions & 1 deletion contracts/interfaces/IVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface IVoter {
error InactiveManagedNFT();
error MaximumVotingNumberTooLow();
error NonZeroVotes();
error NotAPool();
error NotApprovedOrOwner();
error NotGovernor();
error NotEmergencyCouncil();
Expand Down

0 comments on commit ce7f8ee

Please sign in to comment.