Skip to content

Commit

Permalink
allocate rewards instead of distributing
Browse files Browse the repository at this point in the history
  • Loading branch information
trmid committed Sep 20, 2023
1 parent f85d0d1 commit 6c679cf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[submodule "lib/pt-v5-prize-pool"]
path = lib/pt-v5-prize-pool
url = https://github.com/generationsoftware/pt-v5-prize-pool
branch = prod-deploy-1
branch = gen-440-auctions-allocate-fees-instead-of-withdrawreserve-c4-92
[submodule "lib/remote-owner"]
path = lib/remote-owner
url = https://github.com/generationsoftware/remote-owner
Expand Down
6 changes: 3 additions & 3 deletions src/RngRelayAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract RngRelayAuction is IRngAuctionRelayListener, IAuction {
/// @param recipient The recipient of the reward
/// @param index The order in which this reward occurred
/// @param reward The reward amount
event AuctionRewardDistributed(
event AuctionRewardAllocated(
uint32 indexed sequenceId,
address indexed recipient,
uint32 indexed index,
Expand Down Expand Up @@ -178,8 +178,8 @@ contract RngRelayAuction is IRngAuctionRelayListener, IAuction {
for (uint8 i = 0; i < _rewards.length; i++) {
uint96 _reward = _safeCast(_rewards[i]);
if (_reward > 0) {
prizePool.withdrawReserve(auctionResults[i].recipient, _reward);
emit AuctionRewardDistributed(_sequenceId, auctionResults[i].recipient, i, _reward);
prizePool.allocateRewardFromReserve(auctionResults[i].recipient, _reward);
emit AuctionRewardAllocated(_sequenceId, auctionResults[i].recipient, i, _reward);
}
}

Expand Down
54 changes: 43 additions & 11 deletions test/RngRelayAuction.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {

contract RngRelayAuctionTest is Helpers {

/* ============ Mock Errors ============ */
error MockAllocateRewardFromReserve(address to, uint256 amount);

/* ============ Events ============ */

event AuctionCompleted(
Expand All @@ -30,7 +33,7 @@ contract RngRelayAuctionTest is Helpers {
UD2x18 rewardFraction
);

event AuctionRewardDistributed(
event AuctionRewardAllocated(
uint32 indexed sequenceId,
address indexed recipient,
uint32 indexed index,
Expand Down Expand Up @@ -155,22 +158,22 @@ contract RngRelayAuctionTest is Helpers {

mockCloseDraw(0x1234);
mockReserve(100e18);
mockWithdrawReserve(address(this), 10e18);
mockAllocateRewardFromReserve(address(this), 10e18);

vm.expectEmit(true, true, true, true);
emit RngSequenceCompleted(
1,
42
);
vm.expectEmit(true, true, true, true);
emit AuctionRewardDistributed(
emit AuctionRewardAllocated(
1,
address(this),
0,
10e18
);
vm.expectEmit(true, true, true, true);
emit AuctionRewardDistributed(
emit AuctionRewardAllocated(
1,
alice,
1,
Expand All @@ -194,6 +197,35 @@ contract RngRelayAuctionTest is Helpers {
assertEq(r.rewardFraction.unwrap(), 249861091820989143, "reward fraction is about a quarter (halfway through parabola)");
}

function testRngComplete_rewardsAllocated() public {
AuctionResult memory results = AuctionResult({
recipient: address(this),
rewardFraction: UD2x18.wrap(0.1 ether)
});

mockCloseDraw(0x1234);
mockReserve(100e18);
uint completedAt = block.timestamp;
vm.warp(completedAt + auctionDurationSeconds/2);

vm.mockCallRevert(
address(prizePool),
abi.encodeWithSelector(
prizePool.allocateRewardFromReserve.selector,
alice,
22487498263889022870
),
abi.encodeWithSelector(MockAllocateRewardFromReserve.selector, alice, 22487498263889022870)
);
vm.expectRevert(abi.encodeWithSelector(MockAllocateRewardFromReserve.selector, alice, 22487498263889022870));
rngRelayAuction.rngComplete(
0x1234,
completedAt,
alice,
1,
results
);
}

function testRngComplete_maxRewards() public {
rngRelayAuction = new RngRelayAuction(prizePool, address(this), auctionDurationSeconds, auctionTargetTime, 10e18);
Expand All @@ -205,18 +237,18 @@ contract RngRelayAuctionTest is Helpers {

mockCloseDraw(0x1234);
mockReserve(100e18);
mockWithdrawReserve(address(this), 1e18);
mockAllocateRewardFromReserve(address(this), 1e18);


vm.expectEmit(true, true, true, true);
emit AuctionRewardDistributed(
emit AuctionRewardAllocated(
1,
address(this),
0,
1e18
);
vm.expectEmit(true, true, true, true);
emit AuctionRewardDistributed(
emit AuctionRewardAllocated(
1,
alice,
1,
Expand Down Expand Up @@ -250,7 +282,7 @@ contract RngRelayAuctionTest is Helpers {

mockCloseDraw(0x1234);
mockPrizePoolReserve(100e18);
mockWithdrawReserve(address(this), 10e18);
mockAllocateRewardFromReserve(address(this), 10e18);

rngRelayAuction.rngComplete(
0x1234,
Expand Down Expand Up @@ -295,7 +327,7 @@ contract RngRelayAuctionTest is Helpers {

mockCloseDraw(0x1234);
mockReserve(100e18);
mockWithdrawReserve(address(this), 10e18);
mockAllocateRewardFromReserve(address(this), 10e18);

uint completedAt = block.timestamp;
vm.warp(completedAt + auctionDurationSeconds/2);
Expand Down Expand Up @@ -381,10 +413,10 @@ contract RngRelayAuctionTest is Helpers {
);
}

function mockWithdrawReserve(address recipient, uint256 amount) public {
function mockAllocateRewardFromReserve(address recipient, uint256 amount) public {
vm.mockCall(
address(prizePool),
abi.encodeWithSelector(PrizePool.withdrawReserve.selector, recipient, amount),
abi.encodeWithSelector(PrizePool.allocateRewardFromReserve.selector, recipient, amount),
abi.encode()
);
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/DirectIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ contract RewardLibTest is Test {
);
}

function mockWithdrawReserve(address to, uint256 amount) public {
function mockAllocateRewardFromReserve(address to, uint256 amount) public {
vm.mockCall(
address(prizePool),
abi.encodeWithSelector(
prizePool.withdrawReserve.selector,
prizePool.allocateRewardFromReserve.selector,
to,
amount
),
Expand Down

0 comments on commit 6c679cf

Please sign in to comment.