-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ability to donate to the prizes #92
Merged
asselstine
merged 2 commits into
main
from
gen-1081-add-ability-to-contribute-prizes-to-prize-pool
Feb 19, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,6 +230,9 @@ contract PrizePool is TieredLiquidityDistributor, Ownable { | |
/// @notice Records the last shutdown withdrawal for an account | ||
mapping(address vault => mapping(address user => uint24 drawId)) internal _lastShutdownWithdrawal; | ||
|
||
/// @notice The special value for the donator address. Contributions from this address are excluded from the total odds. F2EE because it's free money! | ||
address public constant DONATOR = 0x000000000000000000000000000000000000F2EE; | ||
|
||
/// @notice The token that is being contributed and awarded as prizes. | ||
IERC20 public immutable prizeToken; | ||
|
||
|
@@ -343,7 +346,7 @@ contract PrizePool is TieredLiquidityDistributor, Ownable { | |
/// @param _prizeVault The address of the vault to contribute to | ||
/// @param _amount The amount of prize tokens to contribute | ||
/// @return The amount of available prize tokens prior to the contribution. | ||
function contributePrizeTokens(address _prizeVault, uint256 _amount) external returns (uint256) { | ||
function contributePrizeTokens(address _prizeVault, uint256 _amount) public returns (uint256) { | ||
uint256 _deltaBalance = prizeToken.balanceOf(address(this)) - accountedBalance(); | ||
if (_deltaBalance < _amount) { | ||
revert ContributionGTDeltaBalance(_amount, _deltaBalance); | ||
|
@@ -355,6 +358,13 @@ contract PrizePool is TieredLiquidityDistributor, Ownable { | |
return _deltaBalance; | ||
} | ||
|
||
/// @notice Allows a user to donate prize tokens to the prize pool. | ||
/// @param _amount The amount of tokens to donate. The amount should already be approved for transfer. | ||
function donatePrizeTokens(uint256 _amount) external { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing natspec |
||
prizeToken.transferFrom(msg.sender, address(this), _amount); | ||
contributePrizeTokens(DONATOR, _amount); | ||
} | ||
|
||
/// @notice Allows the Manager to allocate a reward from the reserve to a recipient. | ||
/// @param _to The address to allocate the rewards to | ||
/// @param _amount The amount of tokens for the reward | ||
|
@@ -588,6 +598,22 @@ contract PrizePool is TieredLiquidityDistributor, Ownable { | |
); | ||
} | ||
|
||
/// @notice Returns the total prize tokens donated to the prize pool | ||
/// @param _startDrawIdInclusive Start draw id inclusive | ||
/// @param _endDrawIdInclusive End draw id inclusive | ||
/// @return The total prize tokens donated to the prize pool | ||
function getDonatedBetween( | ||
uint24 _startDrawIdInclusive, | ||
uint24 _endDrawIdInclusive | ||
) external view returns (uint256) { | ||
return | ||
DrawAccumulatorLib.getDisbursedBetween( | ||
_vaultAccumulator[DONATOR], | ||
_startDrawIdInclusive, | ||
_endDrawIdInclusive | ||
); | ||
} | ||
|
||
/// @notice Computes the expected duration prize accrual for a tier. | ||
/// @param _tier The tier to check | ||
/// @return The number of draws | ||
|
@@ -954,12 +980,18 @@ contract PrizePool is TieredLiquidityDistributor, Ownable { | |
uint24 _startDrawIdInclusive, | ||
uint24 _endDrawIdInclusive | ||
) public view returns (SD59x18) { | ||
if (_vault == DONATOR) { | ||
return sd(0); | ||
} | ||
|
||
uint256 totalContributed = DrawAccumulatorLib.getDisbursedBetween( | ||
_totalAccumulator, | ||
_startDrawIdInclusive, | ||
_endDrawIdInclusive | ||
); | ||
|
||
uint256 totalDonated = DrawAccumulatorLib.getDisbursedBetween(_vaultAccumulator[DONATOR], _startDrawIdInclusive, _endDrawIdInclusive); | ||
|
||
// vaultContributed / totalContributed | ||
return | ||
totalContributed != 0 | ||
|
@@ -971,7 +1003,7 @@ contract PrizePool is TieredLiquidityDistributor, Ownable { | |
_endDrawIdInclusive | ||
) | ||
) | ||
).div(sd(SafeCast.toInt256(totalContributed))) | ||
).div(sd(SafeCast.toInt256(totalContributed - totalDonated))) | ||
: sd(0); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing natspec
Also would be nice to know why this address was chosen.