Skip to content

Commit 00107b3

Browse files
committed
Cap Notifier
1 parent a0aa78a commit 00107b3

4 files changed

Lines changed: 84 additions & 3 deletions

File tree

contracts/feeReceiver/FeeReceiver.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ contract FeeReceiver is IFeeReceiver, UUPSUpgradeable, Access, FeeReceiverStorag
3939
if ($.protocolFeePercentage > 0) _claimProtocolFees();
4040
uint256 bal = $.capToken.balanceOf(address(this));
4141
$.capToken.safeTransfer(address($.stakedCapToken), bal);
42-
if ($.stakedCapToken.lastNotify() + $.stakedCapToken.lockDuration() < block.timestamp) {
43-
$.stakedCapToken.notify();
44-
}
4542
emit FeesDistributed(bal);
4643
}
44+
45+
if ($.stakedCapToken.lastNotify() + $.stakedCapToken.lockDuration() < block.timestamp) {
46+
$.stakedCapToken.notify();
47+
}
4748
}
4849

4950
/// @inheritdoc IFeeReceiver

contracts/gelato/CapNotify.sol

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.28;
3+
4+
import { ICapNotify } from "../interfaces/ICapNotify.sol";
5+
6+
import { IFeeReceiver } from "../interfaces/IFeeReceiver.sol";
7+
import { IStakedCap } from "../interfaces/IStakedCap.sol";
8+
9+
import { CapNotifyStorageUtils } from "../storage/CapNotifyStorageUtils.sol";
10+
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
11+
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
12+
13+
/// @title Cap Notifier
14+
/// @author weso, Cap Labs
15+
/// @notice Calls distribute from the Fee Receiver contract
16+
contract CapNotify is ICapNotify, CapNotifyStorageUtils, Initializable {
17+
/// @inheritdoc ICapNotify
18+
function initialize(address _feeReceiver, address _stakedCap) external initializer {
19+
CapNotifyStorage storage $ = getCapNotifyStorage();
20+
$.feeReceiver = _feeReceiver;
21+
$.stakedCap = _stakedCap;
22+
}
23+
24+
/// @inheritdoc ICapNotify
25+
function notify() external {
26+
CapNotifyStorage storage $ = getCapNotifyStorage();
27+
IFeeReceiver($.feeReceiver).distribute();
28+
}
29+
30+
/// @inheritdoc ICapNotify
31+
function checker() external view returns (bool canExec, bytes memory execPayload) {
32+
CapNotifyStorage storage $ = getCapNotifyStorage();
33+
uint256 lastNotify = IStakedCap($.stakedCap).lastNotify();
34+
uint256 duration = IStakedCap($.stakedCap).lockDuration();
35+
if (lastNotify + duration > block.timestamp) return (false, bytes("Not time to notify"));
36+
37+
return (true, abi.encodeCall(this.notify, ()));
38+
}
39+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.28;
3+
4+
interface ICapNotify {
5+
struct CapNotifyStorage {
6+
address feeReceiver;
7+
address stakedCap;
8+
}
9+
/// @notice Initialize the CapNotify contract
10+
/// @param _feeReceiver Fee receiver address
11+
/// @param _stakedCap Staked cap address
12+
13+
function initialize(address _feeReceiver, address _stakedCap) external;
14+
15+
/// @notice Notify the fee receiver
16+
function notify() external;
17+
18+
/// @notice Gelato checker
19+
function checker() external view returns (bool canExec, bytes memory execPayload);
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.28;
3+
4+
import { ICapNotify } from "../interfaces/ICapNotify.sol";
5+
6+
/// @title Cap Notify Storage Utils
7+
/// @author weso, Cap Labs
8+
/// @notice Storage utilities for cap notify
9+
abstract contract CapNotifyStorageUtils {
10+
/// @dev keccak256(abi.encode(uint256(keccak256("cap.storage.CapNotify")) - 1)) & ~bytes32(uint256(0xff))
11+
bytes32 private constant CapNotifyStorageLocation =
12+
0xae7da03710cf6ca7cf92719d8e00ba51842bad60a95a2e09406012de26726900;
13+
14+
/// @dev Get cap notify storage
15+
/// @return $ Storage pointer
16+
function getCapNotifyStorage() internal pure returns (ICapNotify.CapNotifyStorage storage $) {
17+
assembly {
18+
$.slot := CapNotifyStorageLocation
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)