Skip to content

Commit

Permalink
Add correct accounting for courier rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Nov 15, 2023
1 parent fb649b1 commit a930cc7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 22 deletions.
9 changes: 0 additions & 9 deletions core/src/Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ contract Factory {
/// @notice Returns the `Courier` for any given ID
mapping(uint32 => Courier) public couriers;

/// @notice Returns whether the given address has enrolled as a courier
mapping(address => bool) public isCourier;

/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -226,10 +223,6 @@ contract Factory {
//////////////////////////////////////////////////////////////*/

function claimRewards(Lender[] calldata lenders, address beneficiary) external returns (uint256 earned) {
// Couriers cannot claim rewards because the accounting isn't quite correct for them. Specifically, we
// save gas by omitting a `Rewards.updateUserState` call for the courier in `Lender._burn`
require(!isCourier[msg.sender]);

unchecked {
uint256 count = lenders.length;
for (uint256 i = 0; i < count; i++) {
Expand Down Expand Up @@ -260,8 +253,6 @@ contract Factory {
require(couriers[id].cut == 0);

couriers[id] = Courier(msg.sender, cut);
isCourier[msg.sender] = true;

emit EnrollCourier(id, msg.sender, cut);
}

Expand Down
7 changes: 2 additions & 5 deletions core/src/Lender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,12 @@ contract Lender is Ledger {
// Compute portion of fee to pay out during this burn.
fee = (fee * shares) / balance;

// Send `fee` from `from` to `courier.wallet`.
// Send `fee` from `from` to `courier`.
// NOTE: We skip principle update on courier, so if couriers credit
// each other, 100% of `fee` is treated as profit and will pass through
// to the next courier.
// NOTE: We skip rewards update on the courier. This means accounting isn't
// accurate for them, so they *should not* be allowed to claim rewards. This
// slightly reduces the effective overall rewards rate.
data -= fee;
balances[courier] += fee;
Rewards.updateUserState(s, a, courier, (balances[courier] += fee) - fee);
emit Transfer(from, courier, fee);
}

Expand Down
8 changes: 0 additions & 8 deletions core/test/Factory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ contract FactoryTest is Test {
emit EnrollCourier(id, address(this), cut);
factory.enrollCourier(id, cut);

assertTrue(factory.isCourier(address(this)));
(address courier, uint16 cutRec) = factory.couriers(id);
assertEq(courier, address(this));
assertEq(cutRec, cut);
Expand All @@ -115,13 +114,6 @@ contract FactoryTest is Test {
lenders[0] = lender0;
lenders[1] = lender1;

// Couriers cannot claim rewards
vm.prank(address(6789));
factory.enrollCourier(1, 5000);
vm.prank(address(6789));
vm.expectRevert(bytes(""));
factory.claimRewards(lenders, address(6789));

// Set rewards token
vm.prank(factory.GOVERNOR());
factory.governRewardsToken(rewardsToken);
Expand Down

0 comments on commit a930cc7

Please sign in to comment.