-
Notifications
You must be signed in to change notification settings - Fork 2
/
YieldSourcePrizePool.sol
82 lines (67 loc) · 3.35 KB
/
YieldSourcePrizePool.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.7.0;
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/SafeERC20Upgradeable.sol";
import "@pooltogether/yield-source-interface/contracts/IYieldSource.sol";
import "../PrizePool.sol";
contract YieldSourcePrizePool is PrizePool {
using SafeERC20Upgradeable for IERC20Upgradeable;
IYieldSource public yieldSource;
event YieldSourcePrizePoolInitialized(address indexed yieldSource);
/// @notice Initializes the Prize Pool and Yield Service with the required contract connections
/// @param _controlledTokens Array of addresses for the Ticket and Sponsorship Tokens controlled by the Prize Pool
/// @param _maxExitFeeMantissa The maximum exit fee size, relative to the withdrawal amount
/// @param _maxTimelockDuration The maximum length of time the withdraw timelock could be
/// @param _yieldSource Address of the yield source
function initializeYieldSourcePrizePool (
RegistryInterface _reserveRegistry,
ControlledTokenInterface[] memory _controlledTokens,
uint256 _maxExitFeeMantissa,
uint256 _maxTimelockDuration,
IYieldSource _yieldSource
)
public
initializer
{
require(address(_yieldSource) != address(0), "YieldSourcePrizePool/yield-source-zero");
PrizePool.initialize(
_reserveRegistry,
_controlledTokens,
_maxExitFeeMantissa,
_maxTimelockDuration
);
yieldSource = _yieldSource;
// A hack to determine whether it's an actual yield source
(bool succeeded,) = address(_yieldSource).staticcall(abi.encode(_yieldSource.depositToken.selector));
require(succeeded, "YieldSourcePrizePool/invalid-yield-source");
emit YieldSourcePrizePoolInitialized(address(_yieldSource));
}
/// @notice Determines whether the passed token can be transferred out as an external award.
/// @dev Different yield sources will hold the deposits as another kind of token: such a Compound's cToken. The
/// prize strategy should not be allowed to move those tokens.
/// @param _externalToken The address of the token to check
/// @return True if the token may be awarded, false otherwise
function _canAwardExternal(address _externalToken) internal override view returns (bool) {
return _externalToken != address(yieldSource);
}
/// @notice Returns the total balance (in asset tokens). This includes the deposits and interest.
/// @return The underlying balance of asset tokens
function _balance() internal override returns (uint256) {
return yieldSource.balanceOfToken(address(this));
}
function _token() internal override view returns (IERC20Upgradeable) {
return IERC20Upgradeable(yieldSource.depositToken());
}
/// @notice Supplies asset tokens to the yield source.
/// @param mintAmount The amount of asset tokens to be supplied
function _supply(uint256 mintAmount) internal override {
_token().safeApprove(address(yieldSource), mintAmount);
yieldSource.supplyTokenTo(mintAmount, address(this));
}
/// @notice Redeems asset tokens from the yield source.
/// @param redeemAmount The amount of yield-bearing tokens to be redeemed
/// @return The actual amount of tokens that were redeemed.
function _redeem(uint256 redeemAmount) internal override returns (uint256) {
return yieldSource.redeemToken(redeemAmount);
}
}