-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdividendDistibutor.sol
More file actions
101 lines (67 loc) · 3.45 KB
/
dividendDistibutor.sol
File metadata and controls
101 lines (67 loc) · 3.45 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
//@title dividendDistributor.sol
//@notice Upgradeable pull-based dividend distribution (ERC-20 only)
interface IEquityToken{
function balanceOf(address account) external view returns (uint256);
function totalSupply() external view returns (uint256);
// Optional legal action
// function forcedTransfer(address from, address to, uint256 amount) external;
}
contract DividendDistributor is Initializable, AccessControlUpgradeable{
using SafeERC20 for IERC20;
//===================Roles============================
bytes32 public constant FINANCE_ROLE = keccak256 ("FINANCE_ROLE");
//===================STORAGE==========================
IERC20 public equityToken; // share token
IERC20 public payoutToken; // dividend token ( eg., USDT or USDC)
uint256 public totalDividendsDeclared;
mapping (address => uint256 ) public claimed;
uint256 [46] private __gap; // STORAGE GAP
//===================Events==============================
event DividendsDeposited(uint256 amount);
event Claimed (address indexed account, uint256 amount);
//==================Constructor=======================
// @custom : oz-upgrades-unsafe-allow constructor
constructor () {_disableInitializers();}
//===================Initialization============================
function initialize (address admin, address _equityToken, address _payoutToken) public initializer {
__AccessControl_init();
equityToken = IERC20(_equityToken);
payoutToken = IERC20 (_payoutToken);
_grantRole (DEFAULT_ADMIN_ROLE, admin);
_grantRole(FINANCE_ROLE, admin);
}
//=================================Funding===========================
//@notice deposit dividends into the pool
//@dev pull payout tokens from caller via SafeERC20
function depositDividends(uint256 amount) external onlyRole (FINANCE_ROLE){
require (amount > 0, " Zero Amount");
totalDividendsDeclared += amount;
payoutToken. safeTransfer (address(this), amount);
emit DividendsDeposited(amount);
}
//=====================Claims=============================
//@notice claim accrued dividends
function claim( address account) external {
require (account != address (0), "Zero Address");
uint256 entitlement = equityToken.balanceOf(account);
require (entitlement != 0, " No dividends to Pay");
uint amount = entitlement - claimed[account];
require (amount !=0, "Nothing to Pay");
claimed[account] -= amount; // state update b4 transfer
payoutToken. safeTransfer (account , amount);
emit Claimed (account, amount);
}
//@notice view how much an account can claim
//@return unclaimed entitlement
function claimable (address account) external view returns (uint256){
require (account != address (0), "Zero Address");
uint256 unclaimedEntitlement = equityToken.balanceOf(account)- claimed[account];
return unclaimedEntitlement;
}
}