-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHoldersRewardsDistributor.sol
129 lines (116 loc) · 5 KB
/
HoldersRewardsDistributor.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "../interfaces/ERC1363Spec.sol";
/**
* @title Bonding Curve Holder Reward Distributor
*
* @notice Holder reward distributor keeps track of every trade event happening in the curve,
* and based on the amount of shares the holder has, alters the holders' reward weight,
* which directly affects the amount of the distributed rewards between the holders
*
* @notice Holder reward distributor accepts the fees from the curve and distributes these fees
* across shares holders proportionally to their weights
*
* @dev Apart from the `accept(uint256,address)` function designed to accept the fees from the
* curve contract, the implementation must implement receive(), fallback(), and onTransferReceived()
* functions to accept direct payments in both ETH and/or ERC20 payment token
*
* @dev receive() and onTransferReceived() with an empty data field must accept the fee in the same way
* as an accept() function would do, but in a passive way (without ERC20 transfer)
*
* @dev The fallback() and onTransferReceived() with non-empty data field must accept the fee and the trading event;
* trading event encoded in the bytes data field contains the information
* on the trade which resulted in the fee being sent:
*
* - address trader - shares holder/trader
* - bool isBuy - true if shares were bought, false if shares were sold
* - uint256 sharesAmount - amount of shares bought or sold
*
* the values above are packed as data = abi.encode(trader, isBuy, sharesAmount)
* and can be unpacked as (trader, isBuy, sharesAmount) = abi.decode(data, (address, bool, uint256))
*
* if specified, the data field must be parsed by the implementation and its containing data applied;
* standard logic applies, if the data is malformed implementation should throw
*
*/
interface HoldersRewardsDistributor is ERC1363Receiver {
/**
* @dev Fired in `sharesBought` and `sharesSold`
*
* @param trader is a buyer or a seller, depending on the operation type
* @param isBuy true if the event comes from the `sharesBought` and represents the buy operation,
* false if the event comes from the `sharesSold` and represents the sell operation
* @param sharesAmount amount of the shares bought or sold (see `isBuy`)
*/
event SharesTraded(address indexed trader, bool indexed isBuy, uint256 sharesAmount);
/**
* @dev Fired when the fee for the distribution is received
*
* @param feeAmount amount of the fee to distribute between the holders
*/
event FeeReceived(uint256 feeAmount);
/**
* @dev Fired in `claimReward`
*
* @param holder address of the trader (and shares holder) who received the reward
* @param rewardAmount amount of the reward sent
*/
event RewardClaimed(address indexed holder, uint256 rewardAmount);
/**
* @notice ERC20 payment token distributor is bound to
*
* @return paymentToken ERC20 payment token address the contract is bound to,
* or zero zero address if it operates with the plain ETH
*/
function getPaymentToken() external view returns(address paymentToken);
/*
*/
/**
* @notice Notifies the distributor about the trade event
*
* @dev Trade amount specified affects holder's (buyer's) weight when calculating the reward
*
* @param buyer shares buyer (becomes shares holder if not yet), a.k.a trader
* @param amountBought amount of the shares bought
*//*
function sharesBought(address buyer, uint256 amountBought) external;
*/
/**
* @notice Notifies the distributor about the trade event
*
* @dev Trade amount specified affects holder's (seller's) weight when calculating the reward
*
* @param seller shares seller (shares holder), a.k.a trader
* @param amountSold amount of the shares sold
*//*
function sharesSold(address seller, uint256 amountSold) external;
*/
/**
* @notice Executed by the fee sender to send the fee; in case of the ERC20 payment,
* this is the ask to take the specified amount of the ERC20 token of the specified type;
* in case of the ETH payment, the amount must be supplied with the transaction itself
*
* @dev When paying with an ERC20 payment token, sender must approve the contract for
* at least the amount specified before executing this function
*
* @dev Updates the accumulated reward per share
*
* @param feeAmount amount of the fee sent,
* in the case of ETH payment must be equal to msg.value
*//*
function accept(uint256 feeAmount) external payable;
*/
/**
* @notice Executed by the holder to claim entire pending reward
*
* @dev Holder can verify pending reward amount with the `pendingReward` function
*/
function claimTheReward() external;
/**
* @notice Pending (claimable) reward. This is the amount which can be claimed using `claimTheReward`
*
* @param holder the holder address to query the reward for
* @return rewardAmount pending reward amount\
*/
function pendingReward(address holder) external view returns(uint256 rewardAmount);
}