-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathPrizeSplitStrategy.sol
81 lines (66 loc) · 2.75 KB
/
PrizeSplitStrategy.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.6;
import "./PrizeSplit.sol";
import "../interfaces/IStrategy.sol";
import "../interfaces/IPrizePool.sol";
/**
* @title PoolTogether V4 PrizeSplitStrategy
* @author PoolTogether Inc Team
* @notice Captures PrizePool interest for PrizeReserve and additional PrizeSplit recipients.
The PrizeSplitStrategy will have at minimum a single PrizeSplit with 100% of the captured
interest transfered to the PrizeReserve. Additional PrizeSplits can be added, depending on
the deployers requirements (i.e. percentage to charity). In contrast to previous PoolTogether
iterations, interest can be captured independent of a new Draw. Ideally (to save gas) interest
is only captured when also distributing the captured prize(s) to applicable Prize Distributor(s).
*/
contract PrizeSplitStrategy is PrizeSplit, IStrategy {
/**
* @notice PrizePool address
*/
IPrizePool internal immutable prizePool;
/**
* @notice Deployed Event
* @param owner Contract owner
* @param prizePool Linked PrizePool contract
*/
event Deployed(address indexed owner, IPrizePool prizePool);
/* ============ Constructor ============ */
/**
* @notice Deploy the PrizeSplitStrategy smart contract.
* @param _owner Owner address
* @param _prizePool PrizePool address
*/
constructor(address _owner, IPrizePool _prizePool) Ownable(_owner) {
require(
address(_prizePool) != address(0),
"PrizeSplitStrategy/prize-pool-not-zero-address"
);
prizePool = _prizePool;
emit Deployed(_owner, _prizePool);
}
/* ============ External Functions ============ */
/// @inheritdoc IStrategy
function distribute() external override returns (uint256) {
uint256 prize = prizePool.captureAwardBalance();
if (prize == 0) return 0;
uint256 prizeRemaining = _distributePrizeSplits(prize);
emit Distributed(prize - prizeRemaining);
return prize;
}
/// @inheritdoc IPrizeSplit
function getPrizePool() external view override returns (IPrizePool) {
return prizePool;
}
/* ============ Internal Functions ============ */
/**
* @notice Award ticket tokens to prize split recipient.
* @dev Award ticket tokens to prize split recipient via the linked PrizePool contract.
* @param _to Recipient of minted tokens.
* @param _amount Amount of minted tokens.
*/
function _awardPrizeSplitAmount(address _to, uint256 _amount) internal override {
IControlledToken _ticket = prizePool.getTicket();
prizePool.award(_to, _amount);
emit PrizeSplitAwarded(_to, _amount, _ticket);
}
}