Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Apr 11, 2024
1 parent acd26b6 commit 552a6b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
5 changes: 3 additions & 2 deletions solidity/contracts/periphery/Keep3rSponsor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ contract Keep3rSponsor is IKeep3rSponsor {

/// @inheritdoc IKeep3rSponsor
function setBonus(uint256 _bonus) external onlyOwner {
if (_bonus < BASE) revert Keep3rSponsor_LowBonus();
bonus = _bonus;
emit BonusSetted(_bonus);
}
Expand Down Expand Up @@ -130,7 +131,6 @@ contract Keep3rSponsor is IKeep3rSponsor {
// The first call to `isKeeper` ensures the caller is a valid keeper
bool _isKeeper = KEEP3R_V2.isKeeper(msg.sender);
if (!_isKeeper) revert Keep3rSponsor_NotKeeper();
uint256 _initialGas = gasleft();

for (uint256 _i; _i < _execData.length;) {
if (!_sponsoredJobs.contains(_execData[_i].job)) revert Keep3rSponsor_JobNotSponsored();
Expand All @@ -140,9 +140,10 @@ contract Keep3rSponsor is IKeep3rSponsor {
}
}

uint256 _initialGas = gasleft();
openRelay.exec(_automationVault, _execData, feeRecipient);

uint256 _gasAfterWork = gasleft();

uint256 _reward = IKeep3rHelper(KEEP3R_HELPER).getRewardAmountFor(msg.sender, _initialGas - _gasAfterWork);
_reward = (_reward * bonus) / BASE;
KEEP3R_V2.bondedPayment(msg.sender, _reward);
Expand Down
5 changes: 5 additions & 0 deletions solidity/interfaces/periphery/IKeep3rSponsor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ interface IKeep3rSponsor {
*/
error Keep3rSponsor_NoJobs();

/**
* @notice Thrown when the bonus is lower than the base
*/
error Keep3rSponsor_LowBonus();

/*///////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/
Expand Down
27 changes: 20 additions & 7 deletions solidity/test/unit/Keep3rSponsor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,32 @@ contract UnitKeep3rSponsorSetOpenRelay is Keep3rSponsorUnitTest {
}

contract UnitKeep3rSponsorSetBonus is Keep3rSponsorUnitTest {
function setUp() public override {
Keep3rSponsorUnitTest.setUp();
modifier happyPath(uint256 _bonus) {
vm.assume(_bonus > keep3rSponsor.BASE());
vm.startPrank(owner);
_;
}

function testRevertIfCallerIsNotOwner(uint256 _bonus) public happyPath(_bonus) {
_revertOnlyOwner();
keep3rSponsor.setBonus(_bonus);
}

function testRevertIfBonusIsLow(uint256 _bonus) public {
vm.assume(_bonus < keep3rSponsor.BASE());
vm.startPrank(owner);
vm.expectRevert(abi.encodeWithSelector(IKeep3rSponsor.Keep3rSponsor_LowBonus.selector));

keep3rSponsor.setBonus(_bonus);
}

function testSetBonus(uint256 _bonus) public {
function testSetBonus(uint256 _bonus) public happyPath(_bonus) {
keep3rSponsor.setBonus(_bonus);

assertEq(keep3rSponsor.bonus(), _bonus);
}

function testEmitBonusSetted(uint256 _bonus) public {
function testEmitBonusSetted(uint256 _bonus) public happyPath(_bonus) {
vm.expectEmit();
emit BonusSetted(_bonus);

Expand Down Expand Up @@ -455,16 +468,16 @@ contract UnitKeep3rSponsorExec is Keep3rSponsorUnitTest {
address(keep3rHelper), abi.encodeWithSelector(IKeep3rHelper.getRewardAmountFor.selector), abi.encode(_reward)
);

uint256 rewardWithBonus = (_reward * keep3rSponsor.bonus()) / keep3rSponsor.BASE();
uint256 _rewardWithBonus = (_reward * keep3rSponsor.bonus()) / keep3rSponsor.BASE();

vm.mockCall(
address(keep3rV2),
abi.encodeWithSelector(IKeep3rV2.bondedPayment.selector, address(this), rewardWithBonus),
abi.encodeWithSelector(IKeep3rV2.bondedPayment.selector, address(this), _rewardWithBonus),
abi.encode(true)
);

vm.expectCall(
address(keep3rV2), abi.encodeWithSelector(IKeep3rV2.bondedPayment.selector, address(this), rewardWithBonus)
address(keep3rV2), abi.encodeWithSelector(IKeep3rV2.bondedPayment.selector, address(this), _rewardWithBonus)
);

keep3rSponsor.exec(_automationVault, _execData);
Expand Down

0 comments on commit 552a6b5

Please sign in to comment.